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

5 comments

0

Try putting the players variable inside of the while loop. The table that GetPlayers() returns is probably empty.

0

i'll try that

0

is this game R15, since R15 doesnt have Torso but UpperTorso and LowerTorso

0

if it is, just use the player's HumanoidRootPart since thats on R15 and R6

0

it's r6, also i did what artallous said and it worked