So here is the script for the part that I have. I have tried to make the script register when the player clicks so that it takes away from the value of cash overall in the part, but then also gives the player the equal amount of cash.
cash = 2000
script.Parent.ClickDetector.MouseClick:connect(function(hit)
cash = cash - 100
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
wait(1)
end)
if cash == 0 then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
script.Parent.ClickDetector.Destroy()
wait(10)
cash = 2000
script.Parent.Transparency = 0
script.CanCollide = true
Instance.new("ClickDetector", script.Parent)
end
11:09:18.610 - Workspace.Part.Script:6: attempt to index local 'player' (a nil value)
That is the error I received when testing it out by clicking on the part.
Here is my leaderboard script that is referenced in the script in my part.
game.Players.PlayerAdded:connect(function(plr)
local leader = Instance.new("Folder", plr)
leader.Name = "leaderstats"
local cash = Instance.new("IntValue", leader)
cash.Name = "Cash"
end)

3 comments
Thanks, this worked; it's amazing it was that simple!
Accept his answer if it helped
Sorry, I'm new.