✓ Accepted answer
Edit: The ClickDetector Script was not working because I forgot the bracket at the end. It should be fine now.
Don't be afraid to put your scripts on Scripting Helpers, as we are all here for a reason, whether as askers or answerers. To make this, you would simply connect a function to the MouseClick event of ClickDetectors.
script.Parent.MouseClick:Connect(function()
end
The first parameter is the player who clicked it. From there, you can go to the player's leaderstats and add 500 to the value named "Money".
Put inside ClickDetector
script.Parent.MouseClick:Connect(function(player)
if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Money") then
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 500
end
end)
This is assuming that there is already a value inside the player named "leaderstats" and inside that, there is a value named "Money" If not, then put this script inside ServerScriptService.
game.Players.PlayerAdded:Connect(function(player)
local l = Instance.new("Folder")
l.Name = "leaderstats"
local m = Instance.new("IntValue")
m.Name = "Money"
m.Parent = l
l.Parent = player
end)
15 comments
Instead of having the value called "Money" I have it called "Cash" so I am assuming I would change FindFirstChild("money") to ("Cash") and the same for the others?
Im testing this theory now ^.
If the value is called "Cash" then change wherever it says "Money" and put "Cash" instead.
I have tried that but for some reason it seems to not be working. I do put the script inside the clickdetector right?
This is the script inside the part inside the clickdetector: https://imgur.com/a/UI6MY
And these are when Im in test mode inside my player https://imgur.com/a/4Rmcu
That's because there are multiple "leaderstats" in your player. The script takes only one, and sees that there is no "Cash" inside. Did you use the last script I put in the answer? If so, then remove all the other code that creates "leaderstats" in your game.
There might be other scripts in your game that create leaderstats in the player, and they might not be doing it only once.
Should I remove the ones that are creating more leaderstats in the player and use your one instead? I can see how the multiple ones will confuse the script
Probably; Try that.
Alrighty
I deleted the ones creating leaderstats in the player and switched to your ones. Now my tycoon money system has broken. I need to go now so I will look at this later. Thanks for the help so far though.
Wait.. I just tested this in studio, and it turns out that the ClickDetector Script errors due to the fact that I forgot to put an end bracket on the last line. I've fixed it now.
Alright im going to revert my scripts back from the tycoon and then add the end bracket on.
Alright the script works now. Thanks for your help!