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

Players in table don't teleport? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

I'm trying to make a teleport script that teleports every player onto the map that was chosen but it only teleports either the players or the beast (another table in my game). The script looks like this and I can't figure the error out for the life of me:

_G.Players = {}
_G.Beast = {}
local PlayersToChooseFrom = {}

for i, v in pairs(game.Players:GetPlayers()) do
    table.insert(PlayersToChooseFrom, v.Name)
end

-- The map is loaded in here but thats not important, as it already works.

local chosenBeast = math.random(1, #PlayersToChooseFrom)

for i, v in pairs(PlayersToChooseFrom) do
    if i == chosenBeast then
        table.insert(_G.Beast, PlayersToChooseFrom[i])
        table.remove(PlayersToChooseFrom, i)
        workspace[_G.Beast[1]].HumanoidRootPart.CFrame =            
                CFrame.new(workspace.MapStorage.Map.BeastSpawn.Position)
    else
        table.insert(_G.Players, PlayersToChooseFrom[i])
        table.remove(PlayersToChooseFrom, i)
    end
end

-- Below is what doesn't work, but also doesn't error out

for i, v in pairs(_G.Players) do
    local spawns = workspace.MapStorage.Map.Spawns:GetChildren()
    workspace[v].HumanoidRootPart.CFrame = CFrame.new(spawns[i].Position)
end

Thanks in advance for figuring this out. All of the words are spelled correctly (I know because it doesn't error out for me defining nil values).

-Cmgtotalyawesome

0
Line 14 if i == Chosenbeast, change that to V. The V is the actual player. Radstar1 270 — 6y
0
@Radstar1 chosenBeast is a number value so that I know which player will be the beast. Whatever the code pulls as the player during a certain amount of times it ran the code will be chosen cmgtotalyawesome 1418 — 6y
0
workspace[v].HumanoidRootPart.CFrame = CFrame.new(spawns[i].CFrame) Maybe? marijus06 68 — 6y
0
@marijus CFrame is not accepted in a new CFrame value, only positions, thanks for answering though cmgtotalyawesome 1418 — 6y

Answer this question