RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a chain lightning ability and add instructions on how to add the code and use the code"
-- server script (ServerScriptService) local function chainLightning(player, target, range, maxTargets) local visited = {} local function chain(target, remainingTargets) if remainingTargets <= 0 then return end visited[target] = true local targetsInRange = workspace:FindPartsInRegion3WithWhiteList( Region3.new(target.Position - Vector3.new(range, range, range), target.Position + Vector3.new(range, range, range)), {workspace.Players}, maxTargets ) for _, newTarget in ipairs(targetsInRange) do if not visited[newTarget] and newTarget:IsA("Model") and newTarget:FindFirstChild("Humanoid") then visited[newTarget] = true local lightning = Instance.new("Part") lightning.Name = "Lightning" lightning.Parent = workspace lightning.BrickColor = BrickColor.new("Bright blue") lightning.Material = Enum.Material.Neon lightning.Anchored = true lightning.CFrame = CFrame.new(target.Position, newTarget.Position) * CFrame.new(0, 0, -range/2) lightning.Size = Vector3.new(0.2, 0.2, range) newTarget.Humanoid:TakeDamage(10) wait(0.1) chain(newTarget, remainingTargets - 1) lightning:Destroy() end end end chain(target, maxTargets) end -- remote event (ReplicatedStorage) local replicatedStorage = game:GetService("ReplicatedStorage") local chainLightningEvent = Instance.new("RemoteEvent") chainLightningEvent.Name = "ChainLightningEvent" chainLightningEvent.Parent = replicatedStorage chainLightningEvent.OnServerEvent:Connect(function(player, target) chainLightning(player, target, 10, 5) end) Instructions: 1. Create a new script in ServerScriptService and paste the server script code above. 2. Create a RemoteEvent in ReplicatedStorage and name it "ChainLightningEvent". 3. In a LocalScript, you can now call the chain lightning ability by using the following code: ```lua local replicatedStorage = game:GetService("ReplicatedStorage") local chainLightningEvent = replicatedStorage:WaitForChild("ChainLightningEvent") local target = game.Workspace.TargetModel -- Replace this with the actual target model you want to use chainLightningEvent:FireServer(target) ``` Replace "TargetModel" with the actual target model you want to use for the chain lightning ability.