Debounce script not working

Im trying to make a skill move but the debounce isn’t working how do i fix it?


Heres the script

local Player = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local st = game:GetService("StarterGui")
local detroit = rp.Events:WaitForChild("Skill1")
local cam = rp.Events:WaitForChild("Camm")
local UIS = game:GetService("UserInputService")
local debounce = false
local player = game:GetService("Players").LocalPlayer
local value = player:WaitForChild("Cooldown")
local gui = game.StarterGui.MainGui.HUD.SkillsHolder.Slot1.CooldownE

local cooldown = script.Parent.Values.Cooldown.Value

function cameraShake()
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	
	for i=1, 30 do
		local a = math.random(-10,10)/100
		local b = math.random(-10,10)/100
		local c = math.random(-10,10)/100
		
		Humanoid.CameraOffset = Vector3.new(a,b,c)
		
		wait()
	end
	Humanoid.CameraOffset = Vector3.new(0,0,0)
end


UIS.InputBegan:Connect(function(input,isTyping)
	if script.Parent.Values.Equipped.Value == true then
		if isTyping then
			return
		elseif input.KeyCode == Enum.KeyCode.E then
			if debounce == false then
				debounce = true

				detroit:FireServer()
			end
		end
	end
end)

detroit.OnClientEvent:Connect(function()
	local last = tick() - value.Value
	local change = 1 - (last/cooldown)
	gui:TweenSize(UDim2.new(1,0,change,0),"In","Linear",0.3)

	debounce = false
end)

cam.OnClientEvent:Connect(function()
	cameraShake()
end)

It is working, but there’s no yielding/waiting, meaning you can spam it to your heart’s delight. You need to make it yield by adding a wait for a specific amount of time before you can do anything again

so do i add a wait() before the UIS began?

You basically do this, in your code after checking if KeyCode is and setting debounce to true, run the detriot event, then do a wait of one second by wait(1) for example and then debounce to false again, make sure you remove debounce = false from the detriot event

So basically after if debounce == false then, the code iwll look like this

debounce = true
detroit:FireServer()
wait(1)
debounce = false

like this?


UIS.InputBegan:Connect(function(input,isTyping)
	if script.Parent.Values.Equipped.Value == true then
		if isTyping then
			return
		elseif input.KeyCode == Enum.KeyCode.E then
			if debounce == false then

				debounce = true
				detroit:FireServer()
				wait(1)
				debounce = false

If so then it didn’t work?

Is your code like this right now?

local Player = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local st = game:GetService("StarterGui")
local detroit = rp.Events:WaitForChild("Skill1")
local cam = rp.Events:WaitForChild("Camm")
local UIS = game:GetService("UserInputService")
local debounce = false
local player = game:GetService("Players").LocalPlayer
local value = player:WaitForChild("Cooldown")
local gui = game.StarterGui.MainGui.HUD.SkillsHolder.Slot1.CooldownE

local cooldown = script.Parent.Values.Cooldown.Value

function cameraShake()
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	
	for i=1, 30 do
		local a = math.random(-10,10)/100
		local b = math.random(-10,10)/100
		local c = math.random(-10,10)/100
		
		Humanoid.CameraOffset = Vector3.new(a,b,c)
		
		wait()
	end
	Humanoid.CameraOffset = Vector3.new(0,0,0)
end


UIS.InputBegan:Connect(function(input,isTyping)
	if script.Parent.Values.Equipped.Value == true then
		if isTyping then
			return
		elseif input.KeyCode == Enum.KeyCode.E then
			if debounce == false then
				debounce = true
				detroit:FireServer()
				wait(1)
				debounce = false
			end
		end
	end
end)

detroit.OnClientEvent:Connect(function()
	local last = tick() - value.Value
	local change = 1 - (last/cooldown)
	gui:TweenSize(UDim2.new(1,0,change,0),"In","Linear",0.3)
end)

cam.OnClientEvent:Connect(function()
	cameraShake()
end)

If it still doesn’t work, then I think you’re setting the debounce in the wrong script since there’s nothing in this code that debounces that spell

oh, so what should i do then? ```

i have seen a video of something similar to this from the youtuber red playz maybe you should check that?

Where’s the code that handles spell casting?

i started with his script

serverscript in serverscriptservice

local rp = game:GetService("ReplicatedStorage")
local detroit = rp.Events:WaitForChild("Skill1")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local cam = rp.Events:WaitForChild("Camm")

local Damage = 1

local Animation = script:WaitForChild("Animations")
local Meshes = script:WaitForChild("Meshes")

detroit.OnServerEvent:Connect(function(player)
	local Character = player.Character
	local humanoid = Character:WaitForChild("Humanoid")
	local HumRP = Character:WaitForChild("HumanoidRootPart")
	
	local smash = humanoid:LoadAnimation(Animation.Animated)
	smash:Play()
	
	local Effects = Instance.new("Folder", Character)
	Effects.Name = "Effects"
	Debris:AddItem(Effects,3)
	
	smash.KeyframeReached:Connect(function(PunchFrame)
		local Wave = Meshes:WaitForChild("Wave"):Clone()
		Wave.CFrame = HumRP.CFrame * CFrame.new(0,0,-3)
		Wave.Parent = Effects
		Debris:AddItem(Wave,.75)
		
		spawn(function()
			cam:FireClient(player)
		end)
		
		local sound = Instance.new("Sound",Character)
		sound.SoundId = "rbxassetid://464615492"
		sound:Play()
		Debris:AddItem(sound,.75)
		
		local goal = {}
		goal.Size = Wave.Size + Vector3.new(3,3,4)
		local info = TweenInfo.new(.25)
		local tween = TweenService:Create(Wave,info,goal)
		tween:Play()
		
		local goal2 = {}
		goal2.CFrame = Wave.CFrame * CFrame.new(0,0,-75)  
		goal2.Transparency = Wave.Transparency + (1 - Wave.Transparency)
		local info2 = TweenInfo.new(.75,Enum.EasingStyle.Linear)
		local tween2 = TweenService:Create(Wave,info2,goal2)
		tween2:Play()
		
		
		
		
	
		Wave.Touched:Connect(function(hit)
			if hit:IsA("BasePart") then
				if hit.Parent:FindFirstChild("npchum") then
					local EHum = hit.Parent:FindFirstChild("npchum")
					if EHum then
						local debounce = Instance.new("BoolValue", EHum)
						debounce.Name = "Debounce"
						Debris:AddItem(debounce,.75)

						EHum:TakeDamage(Damage)
					end
				end
			end
		end)
		
				
		
		for i=1, 25 do
			local Rocks = Meshes:WaitForChild("Rocks"):Clone()
			Rocks.CFrame = Wave.CFrame * CFrame.new(0,-3,0)
			Rocks.Parent = Effects
			Debris:AddItem(Rocks,3)
			
			local rGoal = {}
			rGoal.Transparency = Rocks.Transparency + (1- Rocks.Transparency)
			local rInfo = TweenInfo.new(3)
			local rTween = TweenService:Create(Rocks,rInfo,rGoal)
			rTween:Play()
			
			wait()
		end
		
	end)
	detroit:FireClient(player)
end)

maybe this could help Debounce Patterns | Documentation - Roblox Creator Hub
im currently in the process of learning lua so if I get stuck i go to the dev hub or the dev forum

oh never mind i had to add a wait longer