I'm trying to make a round script, that teleports four players (, who have triggered some kind of event) onto four spawns, but for some reason, it doesn't work the first time. The first player that steps on the part (in this case), gets teleported, but afterwards, it seems to work normally as intended (teleporting only if four players touched the part.) The script is a "normal" script in ServerScriptService. Also, no errors. Here is my code:
plrsteleporting = {}
game.Workspace.Spawning.Touched:Connect(function(hit) --[["Spawning" is the Part the players step on]]
local maxplayers = game.ServerStorage.PlayersTeleporting.Value
local char = hit.parent
local player = game.Players:GetPlayerFromCharacter(char)
if player then
if maxplayers < 5 then
table.insert(plrsteleporting, player)
maxplayers = maxplayers+1
end
local spawn1 = game.Workspace.Spawns.Spawn1
local spawn2 = game.Workspace.Spawns.Spawn2
local spawn3 = game.Workspace.Spawns.Spawn3
local spawn4 = game.Workspace.Spawns.Spawn4
local player1 = plrsteleporting[1]
local player2 = plrsteleporting[2]
local player3 = plrsteleporting[3]
local player4 = plrsteleporting[4]
if table.getn(plrsteleporting) == 4 then
player1.Character:MoveTo(spawn1.Position)
player2.Character:MoveTo(spawn2.Position)
player3.Character:MoveTo(spawn3.Position)
player4.Character:MoveTo(spawn4.Position)
else
print("There have to be 4 players.")
end
end
end)
(P.S. I'm a beginner at scripting so my script is really bad and inefficient. Thanks in advance!)

2 comments
Okie so why do you say i need to hire a scripter when you are the one that doesn't know how to script i script a lot of stuff OK
bruh, i literally have a problem here and you didn't even make the effort to try scripting