Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make it that when a player clicks on a item, the player gets money in the leaderboard?

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.

3 comments

0

the MouseClick event has a built in argument that is the player who clicked, which you can use to access the Cash object

0

Also, you should refrain from using the second parameter of Instance.new in the future , as using it can have negative effects on performance, due to the way roblox handles property listeners

0

@theking48989987 , what causes it to drop performance? And I assume you should use the two-line approach of thing = Instance.new('Part) and thing.Parent = other_thing?

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.