Debounce isn't working as intended

The debounce doesn’t seem to be working for this, if I spam button1down the text will go between loading and ready

i’ve tried switching to other things and tryna figure out solutions but nothing works

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local SniperGui = plr.PlayerGui:WaitForChild("SniperGui")
local uis = game:GetService("UserInputService")
local remotes = game.ReplicatedStorage.Remotes
local shot = false

SniperGui.Enabled = true

-- // Variables
local mouse = plr:GetMouse()
local equipped = false
mouse.TargetFilter = workspace.Barriers

mouse.Button1Down:Connect(function()
	if equipped and not uis.TouchEnabled then
		if not shot then shot = true end

		local lv = cam.CFrame.LookVector

		remotes.Round.Shoot:FireServer(lv, script.Parent.Nuzzle)

		SniperGui.Reloading.Text = "Reloading"

		task.wait(1)

		SniperGui.Reloading.Text = "Ready!"
		
		shot = false
		wait(0.3)
	end
end)

script.Parent.Equipped:Connect(function()
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
end)

could you show us the whole script?

1 Like

i’ve edited the post and fixed it so it includes the entire script

so basically, what you are doing is

		if not shot then shot = true end
-- even if shot is false, this still gets executed because it's not part for the actual if statement

you can fix this by wrapping the entire script in the if function.

mouse.Button1Down:Connect(function()
	if equipped and not uis.TouchEnabled then
		if not shot then 
        shot = true
		local lv = cam.CFrame.LookVector

		remotes.Round.Shoot:FireServer(lv, script.Parent.Nuzzle)

		SniperGui.Reloading.Text = "Reloading"

		task.wait(1)

		SniperGui.Reloading.Text = "Ready!"
		
		shot = false
		wait(0.3)
	end
end
end)

I dont use not so I’m not sure, but couldnt you just wrap the entire script in if shot == false then, it kind of looks like you’re just setting the debounce to true if its false then running the rest of the script regardless of whether its true or not.

1 Like

oh my god how didn’t i see that thank you for noticing

1 Like

half of the time you just need an extra set of eyes, lol.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.