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
6 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.

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

1 answer

Log in to vote
1
Answered by
brianush1 235 Moderation Voter
6 years ago
01local Spawns = workspace.CurrentMap:FindFirstChild(MapChosen).Spawns:GetChildren()
02 
03for i = 1,PlayerCount do
04    local player = PlayerTable[i] -- store the player in a variable
05    local char = player.Character -- and their character
06    if not player.AFK.Value and char and char.Humanoid.Health > 0 then
07        -- "i" is going to increase, so no point in *removing* any spawns
08        -- since we can easily skip over them
09        char.HumanoidRootPart.CFrame = Spawns[i].CFrame + Vector3.new(0, 2, 0)
10    end
11end

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

0
Thanks man! Mr_Unlucky 1085 — 6y
Ad

Answer this question