Script helping Magnitude

gasblock

local part = game.Workspace.GAZBLOKLARI
local players = game:GetService(“Players”)
game.ReplicatedStorage.GasDamage.OnClientEvent:Connect(function()
for a,b in pairs(part:GetChildren()) do
for i,v in pairs(players:GetPlayers()) do
if workspace.GasEnabled.Value == true then
–coroutine.wrap(function()
while wait(.1) do
local character = v.Character or v.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild(“HumanoidRootPart”)
if (b.Position - humanoidRootPart.Position).magnitude < 25 then
v.Character.Humanoid:TakeDamage(5)
warn(b)
end
end
end
–end)
end
end
end)

my problem: The localscript only working on 1 block

1 Like
coroutine.wrap(function()
   --your code here
end)() --you forgot the () to fire it
1 Like

how should I put this “()”? If I do what you say, a red line appears below the code

Because you made the function a comment --, remove the dashes.

I already deleted it. coroutine.wrap(function()
while wait(.1) do
local character = v.Character or v.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild(“HumanoidRootPart”)
if (b.Position - humanoidRootPart.Position).magnitude < 25 then
v.Character.Humanoid:TakeDamage(5)
warn(b)
end
end
end
end)()

still not working

You have an extra end above end)() now.

game.ReplicatedStorage.GasDamage.OnClientEvent:Connect(function()
for a,b in pairs(part:GetChildren()) do
for i,v in pairs(players:GetPlayers()) do
if workspace.GasEnabled.Value == true then
coroutine.wrap(function()
while wait(.1) do
local character = v.Character or v.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild(“HumanoidRootPart”)
if (b.Position - humanoidRootPart.Position).magnitude < 25 then
v.Character.Humanoid:TakeDamage(5)
warn(b)
end
end
end)()
end
end
end) last end have red line

Add another end above end).