Help with Round Script

Where is mistake in this script?

local function teleportPlayers()
    	local spawns = cMap.Map.spawns:GetChildren()
    	local players = game.Players:GetPlayers()
    	for i,v in pairs(players) do
    		for j=1, #spawns do
    			if spawns[j].active == true then
    				v.Character.HumanoidRootPart.CFrame = spawns[j].CFrame
    				spawns[j].active = false
    			end
    		end
    	end
    	print("Teleported")
    end
1 Like

All of the for loops seem to be scripted correctly so I don’t see any mistake, or maybe I missed it.

Where is the script giving you an error? With what you just sourced I don’t even know where you run the function or how. Are you running it when a player connects? Are you running it on command? Please specify because it’s hard to help with this amount of info.

I’m not teleported to the map

First of all, I would move the print(“Teleported”) statement to inside of your for loop. Second, assure that your spawns are active to begin with. Other than that, that’s all I can see. It’s probably an error with the “Active” statement. Are there any errors in the output?

no error i found and thanks for trying

Can you send an image of your output?
And also are you sure you called the function?

Well, still try out the print statements, see if the For loop is actually doing its job. Something is clearly wrong.

He called the function and he already posted a picture of the output. Function works fine, it’s the loop itself.

Oh, instead of saying :GetPlayers(), try doing :GetChildren(). For whatever reason that always worked for me.

my output:

and i called function

the output after i type :GetChildren()image

local function teleportPlayers()
    	local spawns = cMap.Map.spawns:GetChildren()
    	for i,v in pairs(game.Players:GetChildren()) do
    		for j=1, #spawns do
    			if spawns[j].Active == true then
    				v.Character.HumanoidRootPart.CFrame = spawns[j].CFrame
                                print("Teleported")
    				spawns[j].Active = false
    			end
    		end
    	end
    	
    end

doesn’t working: image

Can you provide more information on:

local spawns = cMap.Map.spawns:GetChildren()

Where is this located? What does it contain? What defines “cMap” ?

There is plenty of information I’m lacking to see here to provide you with any real help.

cMap is located in workspace
contain the currently map
cMap = currently map

Try this:

local function teleportPlayers(player)
    	local spawns = cMap.Map.spawns:GetChildren()
player.Character.HumanoidRootPart = spawns[math.random(1,#spawns)]
    	print("Teleported")
    end
for index, plr in pairs(game.Players:GetChildren()) do
teleportPlayers(plr)
end

Also, I removed the loop, because it’ll teleport the players to all of the spawns instead of just one.

i’m not teleported but this is my output:image

1 Like

I forgot to add .CFrame lol

local function teleportPlayers(player)
    	local spawns = cMap.Map.spawns:GetChildren()
player.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame
    	print("Teleported")
    end
for index, plr in pairs(game.Players:GetChildren()) do
teleportPlayers(plr)
end

Maybe teleport the players LowerTorso? Idk if it makes a difference though

1 Like