In my game I’m trying to make a platform where you touch a part and it’ll put you in a table and teleport anyone who is in the table to a map after a short countdown. However, when I test it out with two players, one player teleports. Can someone show me what’s the issue?
local players = game:GetService("Players")
local part = script.Parent
local touchedPlayers = {}
local function teleportPlayers()
for i, v in pairs(touchedPlayers) do
-- make copy of map from serverstorage and teleport players to the copy
local Map1 = game.ServerStorage.Map1
local Map1Copy = Map1:Clone()
Map1Copy.Parent = workspace
wait(1)
v.Character.HumanoidRootPart.Position = Vector3.new(Map1Copy.Part.Position)
end
end
local function gameCheck()
if #touchedPlayers >= 1 then
wait(5)
teleportPlayers()
print("start game")
else
print("not enough players")
end
end
local debounce = false
part.Touched:Connect(function(hit)
local hitModel = hit:FindFirstAncestorOfClass("Model")
if hitModel then
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if hitPlayer and debounce == false then
debounce = true
game.ReplicatedStorage["TimerGUI"]:FireClient(hitPlayer) -- plays GUI timer
if not table.find(touchedPlayers, hitPlayer) then
table.insert(touchedPlayers, hitPlayer)
gameCheck()
end
end
end
print(touchedPlayers)
end)
players.PlayerRemoving:Connect(function(player)
local tablePlayer = table.find(touchedPlayers, player)
if tablePlayer then
table.remove(touchedPlayers, tablePlayer)
end
end)