Good morning, everyone, So I'm making a tycoon and I want when I pass on the collector, to get the money back so I made this script:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + script.Parent.Parent.Screen.amount.Value end end)
And when I run the script I get the following error: "attempt to index field'LocalPlayer' (a nil value)", I looked on other forums but nothing, I don't know what to do. Help me please
This should work:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- get the player from the character local Cash = Player.leaderstats.Cash Cash.Value = Cash.Value + script.Parent.Parent.Screen.amount.Value end end)
If it helped, remember to accept! :D
Thank you Xviperlink, but now, I have this error: "Player is not a valid member of DataModel"