game.Players.PlayerAdded:Connect(function(Player) print(Player.Name) local debounce = false local function onTouched(part) local human = part.Parent:findFirstChild("Humanoid") if human ~=nil and debounce ~= true and game.Workspace.Gates.Gate1.Transporting1.Value ~= true then debounce = true game.ReplicatedStorage.Enter1:FireClient(Player) end wait(2) debounce = false end end script.Parent.Touched:connect(onTouched) end)
It almost works but it fires it for every player how would i fix this?
you dont need a player added event as you can get the player who touched the part(if a player did) from the touched event, so you can use this as an alternative:
local debounce = false script.Parent.Touched:Connect(function(part) local player = game.Players:GetPlayerFromCharacter(part.Parent) if player and debounce ~= true and game.Workspace.Gates.Gate1.Transporting1.Value ~= true then debounce = true game.ReplicatedStorage.Enter1:FireClient(player) wait(2) debounce = false end end)