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

Tables and CFraming issues, any help?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

Basically, I'm trying to make a spawning system using tables. Every time a player is spawned, the spawn they are going to be spawned in will be removed from the table, so no other player will be sharing their spawn. Afterwards, once everyone is spawned, the game continues. However, it doesn't remove it from the table and instead still makes people share spawns.

I tried making a for loop to find if any of the selected spawns equaled to the index but that didn't work. I also tried following tutorials, but that didn't work. I've been trying to find a fix for a while now, but I eventually gave up. Any help fixing would be greatly appreciated.

for i = 1,PlayerCount do 
        if not PlayerTable[i].AFK.Value and PlayerTable[i].Character and PlayerTable[i].Character.Humanoid.Health > 0 then
            local Spawns = workspace.CurrentMap:FindFirstChild(MapChosen).Spawns:GetChildren()
            local Character = PlayerTable[i].Character
            Character.HumanoidRootPart.CFrame = Spawns[1].CFrame + Vector3.new(0,2,0)
            table.remove(Spawns,1)
        end
    end

1 answer

Log in to vote
1
Answered by
brianush1 235 Moderation Voter
5 years ago
local Spawns = workspace.CurrentMap:FindFirstChild(MapChosen).Spawns:GetChildren()

for i = 1,PlayerCount do
    local player = PlayerTable[i] -- store the player in a variable
    local char = player.Character -- and their character
    if not player.AFK.Value and char and char.Humanoid.Health > 0 then
        -- "i" is going to increase, so no point in *removing* any spawns
        -- since we can easily skip over them
        char.HumanoidRootPart.CFrame = Spawns[i].CFrame + Vector3.new(0, 2, 0)
    end
end

NOTE: this will error if there are more players than spawns

0
Thanks man! Mr_Unlucky 1085 — 5y
Ad

Answer this question