I am trying to create a plot purchase system (i have deleted all the code inside because it is irrelevant). It works fine the first time it is bought but the second time it runs the event twice. I have used print to figure out where it is firing twice and it is from the bottom of the script below.
game.ReplicatedStorage.PlotNumber.OnClientEvent:Connect(function(plotNumber, char)
print("hello") -- this is printing only once
local debounce = false
local buyProperty1 = ReplicatedStorage:WaitForChild('BuyProperty1')
local buyProperty2 = ReplicatedStorage:WaitForChild('BuyProperty2')
local buyProperty3 = ReplicatedStorage:WaitForChild('BuyProperty3')
local function shopMenu()
if debounce == false then
debounce = true
wait (5)
debounce = false
end
end
local function closeMenu()
if debounce == false then
debounce = true
wait (5)
debounce = false
end
end
local function buyProperty1Activate()
if debounce == false then
print("GG") -- this is printing twice
debounce = true
wait (5)
debounce = false
end
end
local function buyProperty2Activate()
if debounce == false then
print("BB") -- this is printing twice
debounce = true
wait (5)
debounce = false
end
end
local function buyProperty3Activate()
if debounce == false then
print("HH") -- this is printing twice
debounce = true
wait (5)
debounce = false
end
end
ReplicatedStorage.OpenBuyGUI.OnClientEvent:Connect(shopMenu)
closeButton.MouseButton1Click:Connect(closeMenu)
buy_1.MouseButton1Click:Connect(buyProperty1Activate)
buy_2.MouseButton1Click:Connect(buyProperty2Activate)
buy_3.MouseButton1Click:Connect(buyProperty3Activate)
-- something here makes it fire twice on the second time something is bought
end)
Thanks in advance, u_fep