✓ Accepted answer
If it's a LocalScript, use LocalPlayer, like this:
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
local char = plr.Character
if char then
char:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(-200, 8, 171.6)
end
end)
However if it's a server script, then either make it a LocalScript or make another LocalScript which will fire a RemoteEvent telling the server script to teleport the player upon clicking the button, like this:
Server Script
local remote = Instance.new("RemoteEvent", game.ReplicatedStorage)
remote.Name = "Remote"
remote.OnServerEvent:Connect(function(plr, arg)
if arg == "TP" then
local char = plr.Character
if char then
char:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(-200, 8, 171.6)
end
end
end)
LocalScript
local remote = game.ReplicatedStorage:WaitForChild("Remote")
script.Parent.MouseButton1Down:Connect(function()
remote:FireServer("TP")
end)
2 comments
Are you making this in R6 or R15
R6