Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help w/ 1 person per spawn?

The script below is in ServerScriptService. What I am trying to do is I have 5 spawns in workspace and only 5 player can be in a server and 1 player has there own spawn. This is not working and I would love some help!

local spawns = {
    workspace.spawn1;
    workspace.spawn2;
    workspace.spawn3;
    workspace.spawn4;
    workspace.spawn5
};

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if table.getn(spawns) > 0 then
            local randomSpawn = spawns[math.random(#spawns)]
                
            character.Torso.CFrame = randomSpawn.CFrame *
            CFrame.new(0,5,0)
        end
    end)
end)

2 comments

1

Why are you using table.getn on one line, but the # operator on the next?

0

Wouldn't it be easier to just use teams if you want them to stick with a single spawn the whole game?

1 answer

✓ Accepted answer

Add a value for each spawn. When a player spawns onto that spawn the value = true so no one else can touch it.

This discussion is preserved as it was. New answers, comments, and votes are closed.