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

Teleporting a Player (Using RemoveEvents)?

I just started learning how to use Remove Events and Functions for FE and I'm having trouble. I'm not entirely sure on how to start. I want to teleport a player to a certain CFrame location when they press a textbutton. I'm also pretty sure I didn't define the player correctly. I didn't know how to define the player from the script, I was confused.

Script in ServerScriptService

local RemoteFunction = Instance.new('RemoteFunction', workspace)
RemoteFunction.Name = "Teleport"

function RemoteFunction.OnServerInvoke(player)
	player.Character.Torso.CFrame = CFrame.new(4775.45, 200.88, -61.63)
end

Script in TextButton

script.Parent.MouseButton1Click:connect(function()
	workspace:WaitForChild("Teleport"):InvokeServer()
end)

1 answer

✓ Accepted answer

The client's character actually replicates to the server, so there is no need to use remotes.

Your script should be a LocalScript with these contents:

local plr = game.Players.LocalPlayers

script.Parent.MouseButton1Click:connect(function()
	plr.Character:SetPrimaryPartCFrame(CFrame.new(4775.45, 200.88, -61.63))
end)

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