01 | game.Players.PlayerAdded:Connect( function (Player) |
02 | print (Player.Name) |
03 | local debounce = false |
04 | local function onTouched(part) |
05 | local human = part.Parent:findFirstChild( "Humanoid" ) |
06 | if human ~ = nil and debounce ~ = true and game.Workspace.Gates.Gate 1. Transporting 1. Value ~ = true then |
07 | debounce = true |
08 | game.ReplicatedStorage.Enter 1 :FireClient(Player) |
09 | end |
10 | wait( 2 ) |
11 | debounce = false |
12 | end |
13 | end |
14 | script.Parent.Touched:connect(onTouched) |
15 | 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:
01 | local debounce = false |
02 |
03 | script.Parent.Touched:Connect( function (part) |
04 |
05 | local player = game.Players:GetPlayerFromCharacter(part.Parent) |
06 |
07 |
08 |
09 | if player and debounce ~ = true and game.Workspace.Gates.Gate 1. Transporting 1. Value ~ = true then |
10 | debounce = true |
11 | game.ReplicatedStorage.Enter 1 :FireClient(player) |
12 |
13 | wait( 2 ) |
14 | debounce = false |
15 |