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

How would I convert this code to select not randomly?

Asked by 6 years ago
Edited 6 years ago

The title is a little odd I know.

Heres what i am trying to do, I want this script to select basically not random. I have a Map and inside the map is a group called "Spawns". I was wondering if there was a way the code (which ill post below) can read from the top of the group to the bottom of the group in that order. Because I have the spawns rotate from green to red team. For example the first spawn in the group is green team and the second spawn is red team and the third spawn is green and you get the point.

So I was wondering if there was a way for the code to read the group from the top down. Sorry if this is a weird question I just really dont know how to ask it any other way.

Heres the code, at the moment it selects spawns at random.

    local spawns = chosemap:WaitForChild("Spawns"):GetChildren()
        for _, player in pairs(game.Players:GetChildren()) do
            enableLockedCamera:FireClient(player)
            if player and #spawns > 0 then
            local uppertorso = player.Character:WaitForChild("HumanoidRootPart")
            local allspawns = math.random()(1, #spawns)
            local randomspawn = spawns[allspawns]
            if randomspawn and uppertorso then
            table.remove(spawns, allspawns)
            uppertorso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 3, 0))
            end
        end
    end

Chose map and enableLockedCamera... Try to ignore those, they are for other features in the game.

Thank you for your time.

1 answer

Log in to vote
0
Answered by 6 years ago
local spawns = chosemap:WaitForChild("Spawns"):GetChildren()
SpawnNum = 1
    for _, player in pairs(game.Players:GetChildren()) do
        enableLockedCamera:FireClient(player)
        if player and #spawns > 0 then
        local uppertorso = player.Character:WaitForChild("HumanoidRootPart")
        local allspawns = SpawnNum
        local randomspawn = spawns[allspawns]
        if randomspawn and uppertorso then
        table.remove(spawns, allspawns)
        uppertorso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 3, 0))
    SpawnNum = SpawnNum + 1
        end
    end
    if SpawnNum == 4 then
    SpawnNum = 1
    end
end
Ad

Answer this question