So I'm trying to make a player TP onto a part once clicked on it, but I get this message:
19:14:06.480 - Workspace.Plate.Script:17: attempt to index upvalue 'Player' (a nil value)
I've already searched for help from here and other places, but they don't fix the issue I have, the script is down below:
local Plate = script.Parent
local Player = game.Players.LocalPlayer
Owned = false
function OnHover()
Plate.BrickColor = BrickColor.Green()
Plate.Material = Enum.Material.Neon
end
function OnLeave()
Plate.BrickColor = BrickColor.Gray()
Plate.Material = Enum.Material.SmoothPlastic
end
function OnClicked()
if Owned == false then
Player.Character:MoveTo(Plate.Position)
Owned = true
end
end
Plate.ClickDetector.MouseClick:connect(OnClicked)
Plate.ClickDetector.MouseHoverEnter:connect(OnHover)
Plate.ClickDetector.MouseHoverLeave:connect(OnLeave)
Hope anyone could help me with this...

1 comment
This code isn't correct as clickdetector is server side but locaplayer is client side, also don't use moveto, change the CFrame on the HumanoidRootPart