Using remote event for Teleport Service isn't working?

  1. What do you want to achieve? I’m trying to make it so that when you click a TextButton, a remote event fires telling the server to teleport that player.

  2. What is the issue? It’s pretty much just not working and there aren’t any errors in the output either.

  3. What solutions have you tried so far? I’ve had a look at this post but this hasn’t helped me either.

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

local remote = ReplicatedStorage:WaitForChild("remoteEvents").BossTP
local ID = 10120257817

remote.OnServerEvent:Connect(function()
	local player = game:GetService("Players").PlayerAdded:Wait()
	print("Teleporting")
	TeleportService:Teleport(ID, player)
end)

Button Script:

local remote = game:GetService("ReplicatedStorage").remoteEvents.BossTP

script.Parent.MouseButton1Click:Connect(function(player)
	remote:FireServer(player)
end)

Really sorry if this is obvious but I just can’t figure it out.

The problem is that you are incorrectly getting the player in the server script. You can get the player from the first parameter of the OnServerEvent event.

Here is your fixed Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

local remote = ReplicatedStorage:WaitForChild("remoteEvents").BossTP
local ID = 10120257817

remote.OnServerEvent:Connect(function(player) -- player on first parameter
	print("Teleporting")
	TeleportService:Teleport(ID, player)
end)
2 Likes

Oh, wow. That flew right over my head for some reason. Thank you!

1 Like