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
Read the comment about your script from me.
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.Cash.Value + player.leaderstats.Cash.Value + 50 player.Character:SetPrimaryPartCFrame(CFrame.new(script.Parent.TeleportPart.Position)) end)
Hope I helped, LennyPlayzYT.