Hi all,
I know this is probably a simple solution, but I’m new and I cannot figure out a solution to this problem: I have a piece of code that, when clicked on, should teleport the player to a random area. I have an issue with getting the player’s HumanoidRootPart, as using LocalPlayer doesn’t seem to work, and using a normal script simply returns “nill”.
Here’s my code (no teleporting code as of right now, but I know how to do it, I just want to figure out why I can’t get the HumanoidRootPart first.):
local button = script.Parent
local function teleport(player)
local humanoid = game:GetService("Players").LocalPlayer:FindFirstChild("HumanoidRootPart")
if humanoid then
print("it works")
end
end
button.MouseButton1Click:Connect(teleport)
As mentioned previously, i’ve tried getting the HumanoidRootPart through LocalPlayer without success, and a normal script doesn’t seem to work as well (player variable returns nill).
Thank you!