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