i tried to make a script where if you touch the part you'll have +50 cash and get teleported back where you started. But when i tested it out it says"Script:5: attempt to index nil with 'WaitForChild' ".Here's the script:
local TPpart = script.Parent
TPpart.Touched:Connect(function(h)
local player = game.Players.LocalPlayer
local Cash = player:WaitForChild("leaderstats").Cash
Cash.Value = Cash.Value + 50
local humanoid = h.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil then
h.Parent.HumanRootPart.CFrame = CFrame.new(script.Parent["TeleportPart"].Position)
end
end)
It would be really nice for someone to explain why this happened and how to fix it :D

1 comment
first of all, the way you defined the player is incorrect. you can not get the localplayer from a server script. the second thing i noticed is that you wrote "HumanRootPart" instead of "HumanoidRootPart" (Line 9)