Script helping Magnitude

Localscript:

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

end)

scriptsc

The problem: Localscripts not working.

A

LocalScripts cannot run if they’re parented inside the workspace, unless if you referenced it inside the Character Model itself

I put a script before, but it didn’t work.

Where is the remote event fired from?

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)

In a gui. and firing local script remote event

So a regular script inside a gui? I don’t see why this is a local script or why you need the remote event.