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

Why doesn't my script teleport all players?

Asked by 5 years ago

Hi, i am creating a game about zombies and i made a map script and it doesn't teleport all the players, am i doing something wrong?

-- Game Script
local maps = game.ReplicatedStorage.Maps:GetChildren()
local gun = game.ReplicatedStorage.TrenchGun
local players = game.Players:GetPlayers()
local intertime = 10
local roundtime = 10
local status = game.ReplicatedStorage.Status
local spawns = game.Workspace.Spawns:GetChildren()
while wait() do
    for i=intertime,1,-1 do
        status.Value = "Intermission: "..i.." seconds remaining."
        wait(1)
    end
    local chosenmap = maps[math.random(1,#maps)]
    local cchosenmap = chosenmap:Clone()
    cchosenmap.Parent = game.Workspace.MapStorage
    status.Value = "Chosen map: "..cchosenmap.Name
    wait(3)
    local spawnpoints = cchosenmap.MapSpawns:GetChildren()
    for i,v in pairs(players) do -- this doesn't work (doesn't teleport players)
        if v.Character then
            v.Character.Torso.CFrame = spawnpoints[math.random(1,#spawnpoints)].CFrame
        end
    end
    for i=roundtime,1,-1 do
        status.Value = "Round: "..i.." seconds remaining."
        wait(1)
    end
    for i,v in pairs(players) do -- this doesn't work (doesn't kill the players)
        if v.Character then
           v.Character.Humanoid.Health = 0
    end
end
end
--[[
    For reference, the spawnpoints are inside a folder, not a group.
--]]
0
Try putting the players variable inside of the while loop. The table that GetPlayers() returns is probably empty. Artallous 2 — 5y
0
i'll try that EnderisLTU0 2 — 5y
0
is this game R15, since R15 doesnt have Torso but UpperTorso and LowerTorso User#23365 30 — 5y
0
if it is, just use the player's HumanoidRootPart since thats on R15 and R6 User#23365 30 — 5y
0
it's r6, also i did what artallous said and it worked EnderisLTU0 2 — 5y

Answer this question