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

How do I make it so that my clickdetector can only be clicked once?

Asked by 6 years ago

In an earlier question I asked how to have a part with a clickdetector inside that gave you 500 cash. That script is now working but I can click it unlimited times and that takes away part of the game as it gives you an unlimited amount of money.

Is there a way that I can have it so when the player clicks the brick they get the 500 (so keeping the other script) but then the brick deletes itself or is unclickable. I need an answer for this as soon as possible please! Many Thanks!

3 answers

Log in to vote
0
Answered by 6 years ago

You could call Destroy() on the clickdetector but this will not be useful because then it will only run once and then it cant be used again until the server shuts down. you could better do something like this that it waits until it can be clicked again.

script.Parent.ClickDetector.MouseClick:Connect(function()
    ---Your script
    script.Parent.ClickDetector.MaxActivationDistance = 0
    wait(10) --The amount of time until you can use the clickdetector again.
    script.Parent.ClickDetector.MaxActivationDistance = 32
end)

Consider accepting this answer if it helped you as it will give us both reputation.

0
I think this is wrong, because the player can just click it again to fire the event, then possibly waiting again for no reason. Consider adding a debounce. Nep_Ryker 131 — 6y
0
You can't click the clickdetector if maxactivationdistance = 0 Timmerman73 85 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

or you can do it by assuming the script is in the same part as the click detector

cooldown = false
waiting = 2

script.Parent.ClickDetector.MouseClick:connect(function(click)
if cooldown == true then return end
print("hi")
cooldown = true
wait(waiting)
cooldown = false
end)

boom prints hi when its clicked and u can only click it every 2 aseconds

0
How do you do that coded format? SoftlockedUnderZero 668 — 5y
Log in to vote
0
Answered by 6 years ago

Alright, I've taken what you wanted and I hope I am not giving you a free script by doing this:

Put this in the Workspace

game.Players.PlayerAdded:Connect(function(plr)

    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats" --Creates the leaderboard

    local score = Instance.new("IntValue")

    score.Name = "Money" --Creates the Money Value
    score.Value = 0 -- Default Money Value, Change it if you don't want this to be default.

    score.Parent = stats    
    stats.Parent = plr
end)

And put this script inside the brick that contains the clickdetector

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if plr.leaderstats.Money.Value >= 499 then -- If the value of money is greater than 499 (500+) then don't do anything
else -- otherwise
    plr.leaderstats.Money.Value = 500 -- Set the Money to 500
    end
end)

If this helped, please accept answer as this gives both of us rep. I spent my time making this.

0
Again, this makes it so all players can use it. DaWarTekWizard 169 — 6y
0
Again, since you didn't provide me your leaderboard script, I've created a new one. For simplicity, feel free to delete the old scripts and use mine instead. :D DaWarTekWizard 169 — 6y

Answer this question