How to teleport my Character using a RemoteEvent?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

How to teleport my Character using a RemoteEvent?

  1. What is the issue? Include screenshots / videos if possible!

How to teleport my Character using a RemoteEvent?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I haven’t tried any solutions so far. I did look for solutions on the Developer Hub.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block
game.Players.LocalPlayer.Character.HumanoidRootPart.Position = game.Workspace.Model.Chinatown.Position

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You can do this by using this format

RemoteEvent.OnServerEvent:Connect(function()
-- teleport player
end)

Or if you want to change it on client you can do it like this
Note I changed OnServerEvent to OnClientEvent

RemoteEvent.OnClientEvent:Connect(function()
-- teleport player
end)

You can also read this for more help. Has everything you need to know about remote events.
https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

3 Likes

How can I do this with a click Function?

function OnClick()

In your localscript, call the :FireServer() method wherever you want in your code, and that will make the OnServerEvent connection run on the server’s side.

1 Like
button.MouseButtonClick:Connect(function()
-- teleport
end)

Read this for some explanation.
https://developer.roblox.com/en-us/api-reference/class/TextButton

1 Like

Apologies if I wasn’t clear enough, but I meant how can I do the RemoteEvent Function while also doing the click Function at the same time?

Put the remote event inside the click function

1 Like

Now my TextButton doesn’t work anymore.

function OnClick()
	game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
script.Parent.MouseButton1Click:Connect(OnClick)

Try putting an end to the function, also do you want it so that when you click your button the remote event will fire and teleport your character?

function OnClick()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end

script.Parent.MouseButton1Click:Connect(OnClick)
1 Like

Yes Yes Yes Yes Yes Yes Yes Yes.

Okay, so since the localscript for the textbutton looks fine as is, you can make your serverscript into something along the lines of

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
   local character = player.Character or player.CharacterAdded:Wait()
   local destination = CFrame.new(0,10,0) -- change 0,10,0 to whatever vector3 u want

   character:PivotTo(CFrame.new(destination))
end)
1 Like

I still got the same result of now my TextButton isn’t working anymore.

function OnClick()
	game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
		local character = player.Character or player.CharacterAdded:Wait()
		local destination = CFrame.new(857.286, 339.376, -98.523) -- change 857.286, 339.376, -98.523 to whatever vector3 u want
		
        character:PivotTo(CFrame.new(destination))
		game.StarterGui.ScreenGui.Frame.Chinatown:Destroy()
	end)
	script.Parent.MouseButton1Click:Connect(OnClick)
end

you don’t need to use a remote event to teleport the character

because the client has network ownership of there own character you can position the character in a localscript

so all you do is

-- LocalScript
local function OnClick()
    game.Players.LocalPlayer.Character:PivotTo(CFrame.new(857.286, 339.376, -98.523))
end

no remote event is needed

1 Like