Client script does somthing for everyone

i used a client script to change the lighting and gravity if they step into a atmosphere and for some reason it does it for everyone

this is my script

 game.Workspace["Planets/moons"].Verdeluna.Verdeluna.atmo.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			for i,v in pairs(script.Parent:GetChildren()) do
				if v:IsA("Sky") or v:IsA("ColorCorrectionEffect") then
					v.Parent = game.Lighting
					game.Workspace.Gravity = 192
					game.Lighting["Milky Way Skybox v2"].Parent = game.ReplicatedStorage
				end
			end
		end
 end)
 
game.Workspace["Planets/moons"].Verdeluna.Verdeluna.atmo.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		for i,v in pairs(game.Lighting:GetChildren()) do
			if v:IsA("Sky") then
				if v.Name == "Clear Noon Sky" then
				v.Parent = script.Parent
				game.Workspace.Gravity = 0
					game.ReplicatedStorage["Milky Way Skybox v2"].Parent = game.Lighting
				end
			end
		end
	end
end)

Other players can still trigger local touch events, so you need to check if they are the LocalPlayer. Try replacing your humanoid check with this condition.

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

zone.Touched:Connect(function(hit)
	if Players:GetPlayerFromCharacter(hit.Parent) == localPlayer then
		-- Set atmosphere
	end
end)

-- Same for TouchEnded
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.