Teleporting players to a part on the map when a button is pressed

When I press a button, I want everyone to teleport to a spot in my game, but I don’t know how to do that. I created my script based off of the script I used to teleport a player between parts when they touched one in a test game I made.

local player = game.Players.LocalPlayer
local TeleportPad = game.Workspace.WoodObbyTeleport

game.ReplicatedStorage.Cutscene3.OnClientEvent:Connect(function()
	player:MoveTo(TeleportPad.Position)
end)

I’ve looked up tutorials here and on youtube but none are activated with a ClickDetector or when a RemoteEvent fires.

Use CFrame.
CFrame the HumanoidRootPart to the CFrame of a part.

game.ReplicatedStorage.Cutscene3.OnClientEvent:Connect(function()
	player.Character:FindFirstChild("HumanoidRootPart").CFrame = TeleportPad.CFrame
end)

It still doesn’t work, I tried taking the HumanoidRootPart out of the line since that worked in my other code, but it didn’t do anything either.

Do you want to teleport All the players on gamę after button click?

Yea
(why does the minimum have to be so high :/)

Did you used :FireAllClients function?

Yea, I have it in ServerScriptService

game.Workspace.CutsceneButton3.CutsceneButton3.ClickDetector.MouseClick:Connect(function() 
	game.ReplicatedStorage.Cutscene3:FireAllClients()
end)

you can make it with only the server instead

game.Workspace.CutsceneButton3.CutsceneButton3.ClickDetector.MouseClick:Connect(function() 
	for _, Player in pairs(game.Players:GetPlayers()) do
		Player.Character.HumanoidRootPart.CFrame = game.Workspace.WoodObbyTeleport.CFrame
	end
end)

Hey! If it’s not already solved, this is what you can try:

If you want to move all players at the same time, I suggest you use a server script. For that, you either use a bindable event instead of the remote event you use now, or you can implement the code directly in the cutscene script.

local TeleportPad = game:GetService("Workspace"):WaitForChild("WoodObbyTeleport") -- MAKE SURE THIS IS A PART
local Players = game:GetService("Players")

game:GetService("ReplicatedStorage"):WaitForChild("Cutscene3").OnServerEvent:Connect(function()  -- YOU CAN USE A BINDABLE EVENT IF YOU FIRE IT FROM THE SERVER AS WELL

	for i, v in pairs(Players:GetPlayers()) do
		v.Character.HumanoidRootPart.Position = TeleportPad.Position
	end

end)

I had to switch it to CFrame, but we’re all good now, thanks!

1 Like