How can I make this so all players will be splited and teleported to different spawnpoints?
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do if plr.Character then plr.Character.HumanoidRootPart.CFrame = spawnpoint.CFrame or spawnpoint2.CFrame or spawnpoint3.CFrame print("All players have been teleported to: "..spawnpoint.Name)
Explanation
You seemed to have misunderstood how or
works; I'll explain it for you real quick.
In your situation or
means:
if spawnpoint1 doesn't exist then choose spawnpoint 2. If spawnpoint2 doesn't exist then choose spawnpoint3.
But I'll assume these 3 spawnpoints will always exist in your game throughout the whole game. Thus using or
will not work here.
Fix
Math.random
fixes this problem and randomly selects a spawnpoint, and then teleports the player to it.
Implementation
for _, player in pairs(game:GetService("Players"):GetPlayers()) do if player.Character then local character = player.Character local index = math.random(1, #workspace.spawnpoints:GetChildren()) local spawnPoint = workspace.spawnpoints:GetChildren()[index] character.HumanoidRootPart.CFrame = spawnPoint.CFrame print("All players have been teleported to: "..spawnpoint.Name) end end
Alright, Thank you for you're help! I suppose that the "spawnpoints" is a folder wich the GetChildren all the things inside gets? However, I get a Infinite yield possible on 'Workspace.Obby:WaitForChild("Spawn")'.
I have changed the location a little bit to where the spawns are located, But it does not work?
The spawns are located at: game.Workspace.Obby.Spawns
for _, player in pairs(game:GetService("Players"):GetPlayers()) do if player.Character then local character = player.Character local index = math.random(1, #workspace.Obby.Spawns:GetChildren()) local spawnPoint = workspace.Obby.Spawns:GetChildren()[index] character.HumanoidRootPart.CFrame = spawnPoint.CFrame print("All players have been teleported to: "..spawnPoint.Name) end end
Can you help me again with this?
Thanks in advice.