Teleporting All Players?

I edited the post and deleted the comment.

I don’t think because, I have a randomizer as a ServerScript:
image
It fires that remoteevent and goes to this code in my localscript:

game.ReplicatedStorage.minigame.OnClientEvent:Connect(function(picked, map)
	game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = picked.."!"
	wait(2)
	if picked == "Swordfight" then
		local text = "Fight to survive!"
		game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = text
		local function teleportAllPlayers(part) -- part being the part you want to TP them to.
    for _,v in pairs(game.Players:GetChildren()) do -- Go through all the players in-game.
        local character = v.Character -- Find their character model.
        if character then
            local humanoidRootPart = character.HumanoidRootPart -- Find their HumanoidRootPart
            if humanoidRootPart then 
                humanoidRootPart.CFrame = map.part.CFrame -- Teleport them!
            end
        end
    end
end
	if picked == "Spinner" then
		local text = "Be the last one standing to win!"
			game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = text
			local function teleportAllPlayers(part) -- part being the part you want to TP them to.
    for _,v in pairs(game.Players:GetChildren()) do -- Go through all the players in-game.
        local character = v.Character -- Find their character model.
        if character then
            local humanoidRootPart = character.HumanoidRootPart -- Find their HumanoidRootPart
            if humanoidRootPart then 
                humanoidRootPart.CFrame = map.part.CFrame -- Teleport them!
            end
        end
    end
end
	if picked == "Obstacle" then
		local text = "Finish first to win!"
				game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = text
			local Players = game:GetService("Players")

local function teleportAllPlayers(part) -- part being the part you want to TP them to.
    for _,v in pairs(game.Players:GetChildren()) do -- Go through all the players in-game.
        local character = v.Character -- Find their character model.
        if character then
            local humanoidRootPart = character.HumanoidRootPart -- Find their HumanoidRootPart
            if humanoidRootPart then 
                humanoidRootPart.CFrame = map.part.CFrame -- Teleport them!
            end
        end
    end

But right now, the teleport doesn’t work. No errors print in the output. (BTW: Map is the chosen minigame.)

This wouldn’t work because:

  1. You’re trying to set the character’s CFrame to a number which won’t work, because it’s supposed to be set to a CFrame.
  2. The player’s character is a Model, which doesn’t have the CFrame property.

You can set the character’s HumanoidRootPart’s CFrame however, since all the limbs are connected to it and it works for every rig. For for the chosen variable, simply index the parts array with chosen and you’ll end up with a random part. You should use the Random object nowadays instead of math.random().

By the way, you shouldn’t spoonfeed people by just dumping the code here, explain the code in detail. Otherwise people will just come again and again in Scripting Support and they’ll just end up relying on others all the time.

Hope this helped!

2 Likes

I’m not sure what you’re getting at with that obfuscated code. Keep in mind you should also use :SetPrimaryPartCFrame().

I changed it before, now it is looking for the characters CFrame

OK guys, I solved it myself, thank you all for helping! I accepted ColeBots answer because that is what I used along with some other things i fixed. Sorry for all the trouble.

1 Like