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!
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.
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
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.