I want to make it that when a player clicks on an item he gets money in the leaderboard. This is a struggle I am dealing with for quite a while so I can hope you guys can help me. I already have the leaderstats folder which goes as follows
game.Players.PlayerAdded:Connect(function(plr) local f = Instance.new("Folder", plr) f.Name = "leaderstats" local cash = Instance.new("IntValue", f) cash.Name = "Cash" cash.Value = 0 end)
And I have the item which changes when a player clicks on it, here is the code of that:
function Money() script.Parent.Money.Decal1.Transparency = 1 script.Parent.Money.Decal2.Transparency = 1 script.Parent.Money.Transparency = 1 script.Parent.ClickDetector.MaxActivationDistance = 0 script.Parent.Cash.Playing = true wait(60) script.Parent.Money.Transparency = 0 script.Parent.Money.Decal1.Transparency = 0 script.Parent.Money.Decal2.Transparency = script.Parent.ClickDetector.MaxActivationDistance = 10 end script.Parent.ClickDetector.MouseClick:Connect(Money)
But I can't figure out how to give value to the Cash file when the players clicks on the money. I hope I am doing it alright, this is my first time on this site so please be kind, thanks for all the help.
Adding on to the comments, I would add a debounce so players cant instantly spam click to get rich. Try this out, I hope it helps! debounce = 0 --let it work
script.Parent.ClickDetector.MouseClick:connect(function(player) --ensure you have a click detector in your model, another way of writing a function if debounce == 0 then --make sure debounce isnt 1 debounce = 0 local players = game.Players:FindFirstChild(player.Name) --find the player who clicked local cash = players:FindFirstChild("leaderstats")["Cash"] --give the cash cash.Value = cash.Value + 0 --whatever value you want here debounce = 1 --set it so they cant click again right away wait(10) --amount of time in seconds to wait debounce = 0 --let them do it again end end)