Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to code if a player clicks a part again the function doesn't happen?

Asked by 7 years ago

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:

1workspace.MyClickDetectorEvent.OnServerEvent:connect(function(plr)
2 
3    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + (5)
4 
5 
6end)

Thank You and help is appreciated

3 answers

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
7 years ago
Edited 7 years ago

You would use the disconnect function for RBXScriptSignals, otherwise known as events.

1local connection
2connection = workspace.MyClickDetectorEvent.OnServerEvent:Connect(function(plr)
3    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 5
4    connection:Disconnect()
5end)
Ad
Log in to vote
0
Answered by
NsNidPL 41
7 years ago
Edited 7 years ago
01workspace.MyClickDetectorEvent.OnServerEvent:connect(function(plr)
02 
03local found = plr.PlayerGui:FindFirstChild("NoAddCash")
04if 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)
09end 
10 
11end)

this should work. not tested

Log in to vote
0
Answered by 7 years ago

If you're talking about all players you could use this:

1local enabled = true --Set enabled to true, so the script is usable
2 
3workspace.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
8end)

Have fun scripting!

Answer this question