I am trying to make a part teleport the player to a part (lets call this door) that is not taken, so that if multiple players touch "door" it will line them up instead of teleporting a player to a position that is taken, but when I run this code it does not stop, and instead goes through all of the parts stopping at the last one.
01 | local Door = script.Parent.Parent |
02 | Door.TeleIn.Touched:Connect( function (p) |
03 | local plr = game.Workspace:WaitForChild(p.Name) |
04 | wait() |
05 | if closed.Value ~ = true then -- if it should teleport the player |
06 | for _,v in pairs (spots:GetChildren()) do -- gets the 'spots' to teleport to |
07 | if v.using.Value ~ = true then -- if that spot is empty |
08 | plr.Humanoid.WalkSpeed = 0 |
09 | plr.HumanoidRootPart.CFrame = CFrame.new(v.Position) -- teleports player |
10 | v.using.Value = true -- sets that position as taken |
11 | break -- this should stop the loop where it is |
12 | end |
13 | end |
14 | end |
15 | end ) |
Add some debounce:
01 | local touch = false |
02 | local Door = script.Parent.Parent |
03 | Door.TeleIn.Touched:Connect( function (p) |
04 | if not touch then |
05 | touch = true |
06 | --do your stuff |
07 | wait( 1 ) --waits 1 second before allowing another touch event to do anything |
08 | touch = false |
09 | end |
10 | end ) |
This will still trigger as many times as it did before, but the difference is that debounce only allows stuff you want to happen once.