Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't this teleport script working?

-------------------------
-- Picks random killer --
-------------------------
	
		players = game.Players:GetChildren()
    	local randomp = players[math.random(1,#players)]
    	print(randomp.Name .. " is killer")
    	randomp.TeamColor = BrickColor.new("Bright red")
    	for i,v in pairs(players)  do
        	if v.Name ~= randomp.Name then
            	print(v.Name .. " is runner")
           	 	v.TeamColor = BrickColor.new("Bright blue")
        	end
    	end

---------------------------------
-- Teleport players to the map --
---------------------------------

		rspawn = mapChosenClone.RunnerSpawn:GetChildren()
		kspawn = mapChosenClone.KillerSpawn:GetChildren()
		
		for i,v in pairs(game.Players:GetChildren()) do
    		name = v.Name
    		check = game.Workspace:FindFirstChild(name)
			if game.Players.TeamColor == "Bright red" then
    			check:MoveTo(kspawn[i].Position)
			elseif game.Players.TeamColor == "Bright blue" then
  				check:MoveTo(rspawn[i].Position)
			end
		end

How can I get this to teleport killers to kspawn and runners to rspawn. It works so it picks a killer and the rest are runners. I need it see if a player is on red team, then move them to a spawn or if their on blue move them to a dif spawn. Only on the teleport part is what needs help.

1 answer

✓ Accepted answer
-------------------------
-- Picks random killer --
-------------------------
	players = game.Players:GetChildren()
	local randomp = players[math.random(1,#players)]
	print(randomp.Name .. " is killer")
	randomp.TeamColor = BrickColor.new("Bright red")
	for i,v in pairs(players)  do
		if v.Name ~= randomp.Name then
			print(v.Name .. " is runner")
			v.TeamColor = BrickColor.new("Bright blue")
		end
	end
---------------------------------
-- Teleport players to the map --
---------------------------------
	rspawn = mapChosenClone.RunnerSpawn:GetChildren()
	kspawn = mapChosenClone.KillerSpawn:GetChildren()

	for i,v in pairs(game.Players:GetChildren()) do
		pcall(function() --To prevent breaking if the Character.Torso is nil
			if v.TeamColor == "Bright red" then
				v.Character.Torso.CFrame=(
					CFrame.new(kspawn[i].Position+Vector3.new(0,3,0))
				)
			elseif v.TeamColor == "Bright blue" then
				v.Character.Torso.CFrame=(
					CFrame.new(rspawn[i].Position+Vector3.new(0,3,0))
				)
			end
		end)
	end

2 comments

0

can I get it so instead of a location, it mvoes to a thing

0

that broke the game

This discussion is preserved as it was. New answers, comments, and votes are closed.