Hello. I’m working on the round system but I have a problem where the script will teleport the player under the baseplate and the player dies. I’ve first thought this is a problem with spawnpoints but is not, all spawnpoints are placed correctly so it must be a problem with code. I don’t know what’s wrong.
This is the function:
local function teleportPlayers()
local spawnpointFolder = currentlyLoadedMap.spawnpoints
local newSword = ServerStorage.Weapons.Sword:Clone()
newSword.Parent = Knight.Backpack
local newStaff = ServerStorage.Weapons.Staff:Clone()
newStaff.Parent = Wizard.Backpack
for _,player in pairs(EveryOne) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = spawnpointFolder:GetChildren()[math.random(1,#spawnpointFolder:GetChildren())].CFrame
else
player:Kick("Invalid player character")
end
end
end
Yeah, I was thinking something more like task.wait(0.5) (30 frames) instead, task.wait() is a single frame. Alternatively move the spawn points slightly above the map (so they hover above the baseplate). You could also add a delay between cloning the map to workspace and teleporting all of the players to it to ensure that the map has loaded.
local spawnPoints = spawnpointFolder:GetChildren()
for i,player in pairs(EveryOne) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = spawnPoints[math.random(1,#spawnPoints)].CFrame
table.remove(spawnPoints,i)
else
player:Kick("Invalid player character")
end
end
This prevents all players from spawning at the same spawn.
I can’t do that because there will be more players than 4 and if there would be more players than 4 spawnpoints the script could not spawn them anywhere