So I set the ResetOnSpawn property of my Screen GUI to false (for a couple of reasons). And so I want my weapon in the GUI able to be equipped one at a time which does work however, after the player dies, the debounce still remains true and the player isn’t able to equip the gun again for some reason. You aren’t able to equip the weapon infinitely, as the weapon is supposed to be produced and by default the amount of times you can equip the weapon is 50 however, the player is only able to equip it just once. Here’s the code:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local weaponamount = game.ReplicatedStorage.Values.WeaponAmountValues:FindFirstChild(script.Parent.Name).Amount
local weaponamounttext = script.Parent.WeaponAmount
local debounce = false
weaponamounttext.Text = weaponamount.Value.." left"
weaponamount:GetPropertyChangedSignal("Value"):Connect(function()
weaponamounttext.Text = weaponamount.Value.." left"
end)
script.Parent.EquipButton.MouseButton1Click:Connect(function()
if weaponamount.Value > 0 then
if debounce == false then
debounce = true
game.ReplicatedStorage.Remotes.Functions.CloneTool:InvokeServer(script.Parent.Name)
game.ReplicatedStorage.Remotes.Events.ChangeWeaponAmount:FireServer(weaponamount)
hum.Died:Connect(function()
if debounce == true then
debounce = false
end
end)
end
end
end)
1 Like
if weaponamount.Value > 0 then
if debounce == false then
debounce = true
game.ReplicatedStorage.Remotes.Functions.CloneTool:InvokeServer(script.Parent.Name)
game.ReplicatedStorage.Remotes.Events.ChangeWeaponAmount:FireServer(weaponamount)
hum.Died:Connect(function()
if debounce == true then
debounce = false
end
end)
end
end
end)
TO
if weaponamount.Value > 0 then
if debounce == false then
debounce = true
game.ReplicatedStorage.Remotes.Functions.CloneTool:InvokeServer(script.Parent.Name)
game.ReplicatedStorage.Remotes.Events.ChangeWeaponAmount:FireServer(weaponamount)
else
debounce = false
end
hum.Died:Connect(function()
if debounce==true then
debounce = false
end
end)
end
end)```
Should be so:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local weaponamount = game.ReplicatedStorage.Values.WeaponAmountValues:FindFirstChild(script.Parent.Name).Amount
local weaponamounttext = script.Parent.WeaponAmount
local debounce = false
weaponamounttext.Text = weaponamount.Value.." left"
weaponamount:GetPropertyChangedSignal("Value"):Connect(function()
weaponamounttext.Text = weaponamount.Value.." left"
end)
script.Parent.EquipButton.MouseButton1Click:Connect(function()
if weaponamount.Value > 0 then
if debounce == false then
debounce = true
game.ReplicatedStorage.Remotes.Functions.CloneTool:InvokeServer(script.Parent.Name)
game.ReplicatedStorage.Remotes.Events.ChangeWeaponAmount:FireServer(weaponamount)
end
end
end)
hum.Died:Connect(function()
if debounce == true then
debounce = false
end
end)
Nah I already did that myself, still didn’t work. But thanks anyway.
Try this out?
local repStore = game:GetService("ReplicatedStorage")
local remotes = repStore.Remotes
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local name = script.Parent.Name
local debounce = false
local weaponamount = repStore.Values.WeaponAmountValues:FindFirstChild(name).Amount
local weaponamounttext = script.Parent.WeaponAmount
weaponamounttext.Text = weaponamount.Value.." left"
weaponamount.Changed:Connect(function(newVal)
weaponamounttext.Text = newVal.." left"
end)
script.Parent.EquipButton.MouseButton1Click:Connect(function()
if weaponamount.Value > 0 then
if not debounce then
debounce = true
remotes.Functions.CloneTool:InvokeServer(name)
remotes.Events.ChangeWeaponAmount:FireServer(weaponamount)
debounce = false -- Remove if needed
end
end
end)
hum.Died:Connect(function()
debounce = false
end)
I’m not sure if you’re purposefully not setting the debounce to false after changing the weapon amount
Idk why u edited ur reply but ur solution did work!
1 Like
Well u have to make debounce equals false in a variable PREFERRED TO BE OUTSIDE OF ANY FUNCTION
And make this
*local db = false
Button.MouseButton1Click:Connect(function()
if db == false then db = true
Run ur code here
Wait(cooldown timer) db = false
end
end)
well i thought it was unnecessary
i have restored it

1 Like