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 6 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:

workspace.MyClickDetectorEvent.OnServerEvent:connect(function(plr)

    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + (5)


end)

Thank You and help is appreciated

3 answers

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

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

local connection
connection = workspace.MyClickDetectorEvent.OnServerEvent:Connect(function(plr)
    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 5
    connection:Disconnect()
end)
Ad
Log in to vote
0
Answered by
NsNidPL 41
6 years ago
Edited 6 years ago
workspace.MyClickDetectorEvent.OnServerEvent:connect(function(plr)

local found = plr.PlayerGui:FindFirstChild("NoAddCash")
if not found then
    local val = Instance.new("BoolValue")
    val.Name = "NoAddCash"
    val.Parent = plr.PlayerGui
    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + (5)
end  

end)

this should work. not tested

Log in to vote
0
Answered by 6 years ago

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

local enabled = true --Set enabled to true, so the script is usable

workspace.MyClickDetectorEvent.OnServerEvent:connect(function(plr)
    if enabled == true then --Checks if the bool is true
        plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + (5)
        enabled = false --Sets the bool to false, making it unusable
    end
end)

Have fun scripting!

Answer this question