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

How do I make a one-time clickable button?

Asked by 4 years ago

I am trying to make a one-time purchase script for in-game currency. I figured out how to make the item the player bought save for when they rejoin but I couldn't figure out how to make the purchase button go away forever. I've made it disappear for when they are in the game but when they rejoin it will obviously be visible again.

local player = game.Players.LocalPlayer
local re = game.ReplicatedStorage.Glowstick

script.Parent.MouseButton1Click:Connect(function()
    if player.stats.Cash.Value >= 1000 then
        re:FireServer()
        wait(0.1)
        script.Parent.Visible = false
    elseif player.stats.Cash.Value < 1000 then
        script.Parent.Parent.Parent.Parent.InvalidAmount.Visible = true
        wait(2)
        script.Parent.Parent.Parent.Parent.InvalidAmount.Visible = false
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

It's simple. You have to use a debounce.

local player = game.Players.LocalPlayer
local re = game.ReplicatedStorage.Glowstick
local debounce = false

script.Parent.MouseButton1Click:Connect(function()
    if player.stats.Cash.Value >= 1000 and debounce == false then
    debounce = true
        re:FireServer()
        wait(0.1)
        script.Parent.Visible = false
    elseif player.stats.Cash.Value < 1000 then
        script.Parent.Parent.Parent.Parent.InvalidAmount.Visible = true
        wait(2)
        script.Parent.Parent.Parent.Parent.InvalidAmount.Visible = false
    end
end)

A debounce is a method commonly used, I don't really know how to explain it but you will understand.

0
That does work but how would I make the purchase button go away forever even when they rejoin again? Asynchronize 16 — 4y
Ad

Answer this question