✓ Accepted answer
Well, I would suggest you to move the player on Server side and not on Local side. Also, use MoveTo property instead of changing the CFrame of HumanoidRootPart. We will also be using RemoteFunction to minimize exploitation.
Local Script :
local RS = game:GetService("ReplicatedStorage")
TextButton.MouseButton1Down:Connect(function()
local plr = game.Players.LocalPlayer
local txt = TextBox.Text
local check, msg = RS.RemoteFunction:InvokeServer(plr.Name, txt)
if check then
TextBox.Text = msg
else
TextBox.Text = msg
end)
Server Script [In ServerScriptService] :
local RS = game:GetService("ReplicatedStorage")
function RS.RemoteFunction.OnServerInvoke(player, doubleChecker, playerTo)
if player.Name ~= doubleChecker then return false, "Exploiter Detected!" end
local char = player.Character or player.CharacterAdded:Wait()
if workspace:FindFirstChild(playerTo) then
local Player = workspace:FindFirstChild(playerTo)
local TeleportPostion = Player.PrimaryPart.Position
char:MoveTo(TeleportPosition)
return true, "Success!"
else
return false, "Could not find"
end
end
Lemme know if it helps! If you want brief explanation of something mentioned above, lemme know!
EDIT : As you told me, if you don't want any type of anti-exploits then, you can simply do the following in a single LocalScript :
TextButton.MouseButton1Down:Connect(function()
local txt = TextBox.Text
local myPlayer = game.Players.LocalPlayer
if game.Players:FindFirstChild(txt) then
local toPlayer = game.Players:FindFirstChild(txt)
local myChar = myPlayer.Character or myPlayer.CharacterAdded:Wait()
local playerChar = toPlayer.Character or toPlayer.CharacterAdded:Wait()
myChar:MoveTo(playerChar.PrimaryPart.Position)
end
end)
2 comments
It would be nice if you could pack this all up into one script without the remote function, i am after all making an admin gui so exploiting isn't really important.
Okay, but if you enconter any case of exploiting, make sure to use RemoteFunctions.