MoveTo: Not working in script in PlayerGUI

I have put a normal script in a button that when clicked will teleport the player to the wanted position. I put it in a normal script as I tried it on a local one and it didn’t work. The fix is probably very simple, but I can’t see it so I need help.

Here is the script I am using.

local Player = script.Parent.Parent.Parent.Parent.Parent
local FlagOwner = script.parent.FlagOwner.Value

script.parent.MouseButton1Click:Connect(function()
	local FlagModel = game.Workspace.SpawnedProps:FindFirstChild(FlagOwner)
	Player.Character:MoveTo(FlagModel.Bottom.Position)
end)

Any help would be appreciated. Thanks :+1:

Try this:

local Player = script.Parent.Parent.Parent.Parent.Parent
local FlagOwner = script.parent.FlagOwner.Value

script.parent.MouseButton1Click:Connect(function()
local FlagModel = game.Workspace.SpawnedProps:FindFirstChild(FlagOwner)
local root = Player.Character:FindFirstChild(“HumanoidRootPart”)
if root then
root.CFrame = FlagModel.Bottom.CFrame
end
end)

1 Like

That hasn’t seemed to work either. :thinking:

The console give you an error?

Nope, nothing is happening. No errors are appearing.

convert it to a LocalScript and change this part

to this

local Player = game:GetService("Players").LocalPlayer

I’ve tried it in a local script, it doesn’t work.

I found the solution. I just created an event and done the teleportation via ServerScriptService.