Workspace.Money.Script:4: attempt to index nil with 'leaderstats'

So basically, I have been trying to make a block that gives you cash when you step on it, but it would print "Workspace.Money.Script:4: attempt to index nil with ‘leaderstats’ " Anyone know how to fix this?
Script:

local MoneyPart = game.Workspace.Money
MoneyPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
    end
end)

You need to define player first.

local MoneyPart = game.Workspace.Money
MoneyPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
    end
end)

Don’t forget to add a debounce to the script too.

1 Like

Thanks, I didn’t know how to do that.