Hi, I am brand new to scripting. I am having trouble with a gui button firing multiple times. When the button is pressed the first time, the code runs once. the second press runs the code twice. the third press runs the code 3 times.
Local Script in Gui (Line 49 is the source of my problem from what i could tell):
local replicatedStore = game:WaitForChild("ReplicatedStorage")
local dropItem = replicatedStore:WaitForChild("dropItem")
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local inventory = player.Inventory
local mainGui = script.Parent
local inventoryGui = mainGui.GUI
local interactGui = player.PlayerGui:WaitForChild("interactGui")
local fullGui = player.PlayerGui:WaitForChild("fullInventory")
local maxSlots = 4
local currentSlots = script.Parent.currentSlots
for i, itemValue in pairs(inventory:GetChildren()) do
itemValue.Quant.Changed:Connect(function()
local itemGui = inventoryGui.itemList:FindFirstChild(itemValue.Name)
if itemGui then
itemGui.ItemQuantity.Text = itemValue.Quant.Value
if itemValue.Quant.Value <= 0 then
itemGui.Visible = false
elseif currentSlots.Value <= maxSlots then
itemGui.Visible = true
end
end
end)
end
for i, itemButton in pairs(inventoryGui.itemList:GetDescendants()) do
if itemButton:IsA("ImageButton") then
itemButton.MouseButton2Up:Connect(function()
local debounce = false
interactGui.Frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
interactGui.Enabled = true
local name = itemButton.Parent.ItemName.Text
local Drop = inventory[name].Drop.Value
local dropButton = interactGui.Frame.Drop
interactGui.Frame.Info.Visible = true
if Drop == true then
interactGui.Frame.Drop.Visible = true
else
interactGui.Frame.Drop.Visible = false
end
local itemVal = inventory[name].Quant.Value
if debounce == false then
debounce = true
dropButton.MouseButton1Down:Connect(function()
if itemVal > 0 then
local dropItem = dropItem:InvokeServer(name)
if dropItem == true then
if itemVal > 0 then
itemButton.Parent.ItemQuantity.Text = itemVal
else
itemButton.Parent.ItemQuantity.Text = itemVal
itemButton.Parent.Visible = false
end
end
end
wait(1)
debounce = false
end)
end
end)
end
end
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if interactGui.Enabled == true then
interactGui.Enabled = false
end
end
end)

2 comments
too big of script Its kinda hard to find the problem I recommend posting the main part you believe the error is on
Sorry for the large script. I seem to have found the source of the problem, but cant find a solution. Post is edited.