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

Why is the debounce not preventing multi inputs?

Hi, i want to make a machine that takes in an item when you press E and then works for some seconds and gives out another item. But somehow i can still spam E and its taking in more items. SHouldnt the debounce prevent this?

local rs = game:GetService("ReplicatedStorage")
local s = game:GetService("ServerStorage")
local sg = rs:WaitForChild("ShowGui")
local input = game:GetService("UserInputService")
local ti = rs:WaitForChild("TakeItem")
local giveitem = rs:WaitForChild("GiveItem")
local d = false
local c = script.Parent.ClickDetector
local a = 0
local e = false

c.MouseHoverEnter:Connect(function(plr)
	
	
	local mouse = plr:GetMouse()
	sg:FireClient(plr, "Desk", "Open", false)
	c.MouseHoverLeave:Connect(function(plr)
		sg:FireClient(plr, "Desk", "Close", false)
	end)
	
	
	--if d == false then
	--	d = true
	mouse.KeyDown:Connect(function(key)
		
		if key == "e" and mouse.Target.Name == "Board" then
			if d == false then
				d = true
				c.MaxActivationDistance = 0
				if ti:InvokeClient(plr, "Metal") == true then
				script.Parent.Model3.gui.BillboardGui.Enabled = true
				wait(5)
				script.Parent.Model3.gui.BillboardGui.Enabled = false
				
				local found = s.Items:FindFirstChild("Duct Tape"):Clone()
				local item = Instance.new("ImageButton", workspace)
				item.Name = found.Name
				item.Size = UDim2.new(0,35,0,35)
				item.Position = UDim2.new(0,11,0,11)
				item.Image = found.Image
				item.BackgroundTransparency = 1
				item.BorderSizePixel = 0
				item.ZIndex = 3
				
				
				
				giveitem:InvokeClient(plr, item)
				end
			else
				print("Not enough Metal")
			end
			
			c.MaxActivationDistance = 20
			d = false
		end
			print("Error")
			print(key)
			print(mouse.Target.Name)
			c.MaxActivationDistance = 20
			d = false
		end)
		
		
end)
	--end
	


3 comments

0

I would check to see if the if statement on line 30 is working. If you have any additional questions comment below my answer.

0

No problem!

0

You’re trying to capture user input from the server, which is not okay.

1 answer

✓ Accepted answer

The main problem is that nowhere in your script do you have a wait() for any amount of time between where you set d to true and where you set it to false. I do see a wait on line 32 but if the if statement is not working then the script will not wait. I don't know how you need your script to work so I cannot tell you where to put the wait but try to put it in a place where it cannot possibly be missed. Hope this helps and have a great day scripting!

1 comment

0

Thx for your reply. I think there was a way around the debounce thats why it spammed. It works now.

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