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...
I believe that localPlayer only works in local scripts that are in the player scripts.
This solution utilizes the player variable of MouseClick. You just have to put it into the function as a parameter.
local Plate = script.Parent 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(parameterA) -- Receive player parameter if Owned == false then parameterA.Character:MoveTo(Plate.Position) Owned = true end end Plate.ClickDetector.MouseClick:connect(OnClicked(player)) -- Fire the function with the player parameter included. Plate.ClickDetector.MouseHoverEnter:connect(OnHover) Plate.ClickDetector.MouseHoverLeave:connect(OnLeave)
This is made for server scripts, by the way. I hope this solves your problem!