How can I make this debounce work for the click?

  1. What do you want to achieve? A debounce that stops this script from spamming.

  2. What is the issue? There’s a debounce on message but the players can still spam click to fire the remote event.
    here’s what happens:
    https://gyazo.com/fb6fe4ab5bf413b4aa00b0a1f3227390

  3. What solutions have you tried so far? none because I dont understand it

here’s my code:

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local RS = game:GetService("ReplicatedStorage")
local Explode = RS.Remotes:WaitForChild("Explode")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local debounce = false
local connect

player.Chatted:Connect(function(msg)
	local spell = string.lower(msg)
	if spell == "infalmmeatur" then
		if not debounce then
			debounce = true
			if Character.Practitioner.Value == true then
				if Character.Magic.Value > 65 then
					connect = mouse.Button1Down:Connect(function()
						local position = mouse.Hit.p
						local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
						Anim:Play()
						Explode:FireServer(position)
					end)
				end
			end
		end
	end
	task.wait(10)
	debounce = false
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like
player.Chatted:Connect(function(msg)
	local spell = string.lower(msg)

	if spell == "infalmmeatur" then
		if not debounce then
			debounce = true

			if Character.Practitioner.Value == true then
				if Character.Magic.Value > 65 then
					connect = mouse.Button1Down:Connect(function()
						local position = mouse.Hit.p
						local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)

						Anim:Play()
						Explode:FireServer(position)
					end)
				end
			end

			task.wait(10)
			debounce = false
		end
	end
end)

just set debounce to false inside the if statement, not outside

2 Likes

hm, still letting me spam. would it work if I set the debounce to false right after the event is fired?

1 Like

oh my bad, I feel a bit blind right now

you need to put the debounce inside the Button1Down connection

that’s why you can still spam

1 Like

ohh I see it now. Thank you! dont mind this

1 Like
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local RS = game:GetService("ReplicatedStorage")
local Explode = RS.Remotes:WaitForChild("Explode")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local debounce = false
local connect

player.Chatted:Connect(function(msg)
	if debounce then
		return 
	end
	local spell = string.lower(msg)
	if spell == "infalmmeatur" then
		if Character.Practitioner.Value == true then
			if Character.Magic.Value > 65 then
				connect = mouse.Button1Down:Connect(function()
					debounce = true
					local position = mouse.Hit.p
					local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
					Anim:Play()
					Explode:FireServer(position)
					task.wait(10)
					debounce = false
				end)
			end
		end
	end
end)
1 Like