Remote Event to teleport local player?

So I’m making admin command gui and I just need to make a remote event that teleports a localplayer to a part. The thing is that I don’t know how to teleport the player through a remote event since I’m using a localscript for the admin.

LocalScript:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleporter = workspace:WaitForChild("Part")
local player = Players.LocalPlayer
local TeleportPlayer = ReplicatedStorage:WaitForChild("TeleportPlayer")

TeleportPlayer:FireServer(Teleporter)

Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AdminsTable = {}
local TeleportPlayer = ReplicatedStorage.TeleportPlayer

TeleportPlayer.OnServerEvent:Connect(function(player, Part)
	if typeof(Part) == "Instance" then
		if Part:IsA("Part") then
			if table.find(AdminsTable, player.UserId) then
				if player.Character then
					player.Character:PivotTo(player.Character:GetPivot()*CFrame.new(Part.Position))
				end
			end
		end
	end
end)
1 Like

Thank you very much I will try this

Don’t know how for sure but try moving the humanoid to the part position with UDim2

That’s a very vague and also very wrong suggestion, but Buzzes is most likely going to work.

Although looking at @iBuzzes code, there’s likely to be a problem with the fact that it’s setting an offset to the Pivot as though it’s an absolute/origin CFrame instead…

1 Like
TeleportPlayer.OnServerEvent:Connect(function(Player, Part)
	local Character = Player.Character
	if table.find(AdminsTable, Player.UserId) then
		Character:PivotTo(Part.CFrame)
	end
end)

Exactly how is this safe? Having admin inside a localscript is the worst idea!

This worked thank you very much.

You don’t need to use a remote event to teleport a player because the player has network ownership of its character

so inside the localscript simply do

game.Players.LocalPlayer.Character:PivotTo(Part.CFrame)

and it will work

1 Like