Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My Shop GUI doesn't debounce properly. Can anyone help?

I made a shop GUI completely with scripts, GUIs, and all the other stuff you need to make a Shop GUI. There's a problem. I just started learning how to use debounces from blackoragnge3343 (thanks btw) and it's still not "debouncing" properly. When I choose for example, Adurite Knife. It does give me one knife. But the next knife I choose (American Knife) gives me 2 instead of 1. Next thing I chose was the Canadian Knife, and it gives me 3. When I try the ban hammer, it doesn't give me anything at all. Can anyone help where I should put my debounces on again? or is it a script problem?

aduritecost = 500
americancost = 1000
--banhammer = admin
canadiancost = 1000
cupcakecost = 100
--devknife = developers
diecost = 100
dogecost = 250
galaxycost = 800
goldencost = 5000
koolcost = 400
mediccost = 500
missingtexturecost = 1800
moneycost = 10000
nightvisioncost = 500
noobcost = 50
robloxcost = 500
rainbowcost = 2500
unicorncost = 10000
tediorecost = 7500
ukcost = 1000
yeetcost = 15000

local player = game.Players.LocalPlayer

local shopgui = player.PlayerGui:WaitForChild("ShopGUI")
local shopmaster = shopgui:WaitForChild("ShopMaster")
local pages = shopmaster:WaitForChild("Pages")
local knives = pages:WaitForChild("Knives")
local description = knives:WaitForChild("Description")
local purchasesound = knives:WaitForChild("PurchaseNoise")

local replicatedstorage = game:GetService("ReplicatedStorage")
local knifestorage = replicatedstorage:WaitForChild("KnifeStorage")

local knifename = description:WaitForChild("ItemName")
local buy = description:WaitForChild("BuyButton")

local debounce = false

function onKnifePurchased()
if not debounce then
debounce = true
	buy.MouseButton1Down:connect(function()
if knifename.Text == ("Adurite Knife") then
if player then
local leaderstats = player:findFirstChild("leaderstats")	
local coins = leaderstats:findFirstChild("Coins")
if coins.Value >= aduritecost then
coins.Value = coins.Value - aduritecost
knifestorage:findFirstChild("Adurite Knife"):clone().Parent = player.Backpack
wait()
debounce = false
end
end
			
elseif knifename.Text == ("American Knife") then
if player then
local leaderstats = player:findFirstChild("leaderstats")	
local coins = leaderstats:findFirstChild("Coins")
if coins.Value >= americancost then
coins.Value = coins.Value - americancost
knifestorage:WaitForChild("American Knife"):clone().Parent = player.Backpack
wait()
debounce = false
end
end
		
elseif knifename.Text == ("Ban Hammer") then
if not debounce then
debounce = true
if player.Name == "randomnamelmao" or "Jxemes" then
knifestorage:WaitForChild("Ban Hammer"):clone().Parent = player.Backpack
wait()
debounce = false
end	
end
			
elseif knifename.Text == ("Canadian Knife") then
if player then
local leaderstats = player:findFirstChild("leaderstats")	
local coins = leaderstats:findFirstChild("Coins")
if coins.Value >= canadiancost then
coins.Value = coins.Value - canadiancost
knifestorage:WaitForChild("Canadian Knife"):clone().Parent = player.Backpack
wait()
debounce = false
end
end			

end		
end)
end
end
knifename.Changed:connect(onKnifePurchased)
buy.Changed:connect(onKnifePurchased)

1 answer

✓ Accepted answer

I already know your problem, in this case, you need to create more debounces. This is because if you set a debounce to false or change it from 1 button, it will effect the next button. For example:

local d = false -- debounce
local b = script.Parent
local b2 = script.Parent.Parent -- not possible just an example

b.MouseButton1Down:Connect(function()
	if d == false then
		d = true
		-- you code
		d = false
end)

though this example isn't "great". So here's a few steps I came up that you can try to fix your script;

  1. Add as many debounces as knives you have. d1 = false d2 = false d3 = false then use a debounce for every elseif
  2. from line 57 look down, you don't see any if not debounces, try adding a if not debounce then to line 57
  3. re organize your script, your script looks messy, when that happens to me I rewrite everything and sometimes find a error
  4. Add print's to find out maybe where the script isn't firing and functioning

Try these steps, start from step 2 to 1 to 3 to 4 because I meant to put 2 as 1. Check your script and you will find problems.

Good Luck and Have Fun

2 comments

0

I did your 1st step and it already works! You, I have to say, are one of the best scripting helpers. Not only to give the answer, you also provide steps of how to do it, tips, and it's organized! Really awesome, and thanks again!

0

Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.