What do you want to achieve? I Want It To Be As Safe As Possible I’m Just Thinking What If The Player Failed To Teleport.
What is the issue? There’s No Issue But Sometime When I Teleport To The Game It Doesn’t Fire
What solutions have you tried so far? I Tried Waiting For 10 Second Before Firing But What If The Player Joined Late
while wait(1) do
for i,v in pairs(game.Players:GetPlayers()) do
task.spawn(function()
if not table.find(playerTable, v.Name) then
local Character = v:LoadCharacter()
playersNeeded = playersNeeded + 1
table.insert(playerTable,v.Name)
end
end)
end
if playersNeeded == #game.Players:GetPlayers() then
print("Test")
startGame.Play()
break
end
end
That while loop is useless and you can save up resources by replacing it with the PlayerAdded and PlayerRemoving events.
local playersNeeded = 5 -- minimum number of players change it as you please
game.Players.PlayerAdded:Connect(function(player)
if not table.find(playersTable, player.UserId then -- it is generally better to use user ids rather than usernames in these situations
-- your v is now player
-- load character
-- increasing the playersNeeded var is redundant
end
if playersNeeded == #playersTable then
-- start the game
table.clear(playersTable) -- reset for a new round
end
end)
game.Players.PlayerRemoving:Connect(function(player)
-- check if the player is in playersTable and if yes then remove them
end)
In this case though using a table is useless since it is going to add all the players in the game anyway.
I don’t understand what you are trying to do via your description? Are you trying to teleport a single player somewhere and have a fall back in case it fails?
no there can be 4 players max and i want the game to wait for all the player that is teleporting and incase someone failed to teleport it will detect it and not wait for that one person
Ok, so when an experience starts, it should wait for at least 4 players to join? And if 4 players don’t join within a certain time, then it should do something else?
You would have to do that completely different than how you have it setup now. If the goal is to count players as they enter the server and then after a timeout, start the experience, you have more variables to account for than just the number of players like experience loading delay, experience running load, latency for connecting players, etc. Just using a raw 10 second timer will only work in ideal, testing circumstances and not reflect how live servers behave.