local part = script.Parent
local players = game:GetService(“Players”)
game.ReplicatedStorage.GasDamage.OnClientEvent:Connect(function()
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 (part.Position - humanoidRootPart.Position).magnitude < 50 then
v.Character.Humanoid:TakeDamage(5)
end
end
end)
end
end
Put it inside StarterPlayerScripts instead, if you’re referencing a RemoteEvent to receive its client event & reference the part again
local part = --Location of Part here
local players = game:GetService("Players")
game.ReplicatedStorage.GasDamage.OnClientEvent:Connect(function()
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 (part.Position - humanoidRootPart.Position).magnitude < 50 then
v.Character.Humanoid:TakeDamage(5)
end
end
end)
end
end
end)