I am trying to make a coin but when I play I get this error: Workspace.Coin.Script:4: attempt to index nil with 'leaderstats'
When I walk over the coin it works fine but it doesn't respawn.
My code
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Cash.Value >= 0 then
wait()
script.Disabled = true
script.Parent.Transparency = 1
script.Parent.CanCollide = false
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 5
wait(1)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
script.Disabled = false
end
end)

1 comment
Try to print(plr)