Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I prevent people from spawning at the same spawn?

Asked by 6 years ago

In my minimap's there are 25 spawns. My problem is that there's a 1 in 25 chance of someone being spawned in the same place, and I'm trying to prevent this. How do I prevent no two people from spawning at the same spawn? Thank you!

function MovePlayers()
    local Players = game.Players:GetPlayers()
    local Spawnso = game.Workspace.Map.Spawns:GetChildren()
    for i, v in pairs(Players) do
        local ToSpawn = math.random(1, #Spawnso)
        if v.GameBool.Value == true then
        v.Character.HumanoidRootPart.CFrame = Spawnso[ToSpawn].CFrame * CFrame.new(0,5,0)
        v.Ingame.Value = true
        -- the last part is probably not needed but oh well
        wait(0.05)
        v.Character.Torso.Anchored = true
        end
    end
end

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago
Edited 6 years ago

You could make a table; once you spawn a player at a part, place that part inside the table, or move it to a different directory. You can check if that part is allready in the table, if it is, don't spawn the player there and retry. I personally would prefer moving the part to a different parent.

0
How do I place it inside a table? bigbenbennett 18 — 6y
0
table.insert(TABLE table, ANY, NUMBER Position) H4X0MSYT 536 — 6y
0
How do i make an if statement or function of when a player spawns at a point? bigbenbennett 18 — 6y
Ad

Answer this question