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

How can I teleport certain players to certain spawns?

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

---------------------------------
-- Teleport players to the map --
---------------------------------
		
spawns = mapChosenClone.Spawns:GetChildren()
for i,v in pairs(game.Players:GetChildren()) do
	name = v.Name
	check = game.Workspace:FindFirstChild(name)
		if check then
			checkHumanoid = check:FindFirstChild("Humanoid")
			if checkHumanoid then
				check:MoveTo(spawns[i].Position)
		end
	end
end

Ok so what I have the script do is pick 1 random player to be a killer and the rest are runners. I need the Teleport part of the script to teleport the runners to a certain brick and the killer to another brick, like deathrun. Could I insert a BoolValue or stringvalue, that when the Killer is chosen they get a boolvalue and then tps the killer to a certain block within the map. Anyone know what I am doing wrong?

1 answer

✓ Accepted answer

You don't really need to waste space with that, just set the value using the script. Try this:

-------------------------
-- Picks random killer --
-------------------------

players = game.Players:GetChildren() 
randomp = players[math.random(#players)]
print(randomp.Name .. " is killer")
for i,v in pairs(players)  do 
if v.Name ~= randomp.Name then
        print(v.Name .. " is runner")
	killer = v.Name
    end
end

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

spawns = mapChosenClone.Spawns:GetChildren()
for i,v in pairs(game.Players:GetChildren()) do
    name = v.Name
    check = game.Workspace:FindFirstChild(name)
        if check then
            checkHumanoid = check:FindFirstChild("Humanoid")
            if checkHumanoid and name ~= killer then -- name is the name of the player, yes?
                check:MoveTo(spawns[i].Position)
            elseif checkHumanoid and name == killer then
		check:MoveTo() -- Dont forget to put in the coordinates. I dont know where the spawn is.
        end
    end
end

2 comments

0

That works, but its like deathrun. I need it so when the killer is chosen it asks if player is killer then change teamcolor to red. Then I need if teamcolor = red then MoveTo(RedSpawn) thats what I need, not coordenates

0

Also line 25 "name" == v.Name

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