I made this code that if a player clicks on a part they get five cash, how do I add that if the player has already clicked on the part once the second time they press it it doesn't award the player with money?
My Clickdetector event code:
1 | workspace.MyClickDetectorEvent.OnServerEvent:connect( function (plr) |
2 |
3 | plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + ( 5 ) |
4 |
5 |
6 | end ) |
Thank You and help is appreciated
You would use the disconnect function for RBXScriptSignals, otherwise known as events.
1 | local connection |
2 | connection = workspace.MyClickDetectorEvent.OnServerEvent:Connect( function (plr) |
3 | plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 5 |
4 | connection:Disconnect() |
5 | end ) |
01 | workspace.MyClickDetectorEvent.OnServerEvent:connect( function (plr) |
02 |
03 | local found = plr.PlayerGui:FindFirstChild( "NoAddCash" ) |
04 | if not found then |
05 | local val = Instance.new( "BoolValue" ) |
06 | val.Name = "NoAddCash" |
07 | val.Parent = plr.PlayerGui |
08 | plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + ( 5 ) |
09 | end |
10 |
11 | end ) |
this should work. not tested
If you're talking about all players you could use this:
1 | local enabled = true --Set enabled to true, so the script is usable |
2 |
3 | workspace.MyClickDetectorEvent.OnServerEvent:connect( function (plr) |
4 | if enabled = = true then --Checks if the bool is true |
5 | plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + ( 5 ) |
6 | enabled = false --Sets the bool to false, making it unusable |
7 | end |
8 | end ) |
Have fun scripting!