So here, I made a simple UserInputService system which fires a remote event when a key is pressed.
The issue is, when the Duration of the spell is done, you can do the spell again.
What’s supposed to happen is, when the duration is done, it waits the cooldown aswell. And once the cooldown is done you can do it.
I tried printing debounce and it prints false everytime, even tough I only changed it back to false after the cooldown and not after the duration.
uis.InputBegan:Connect(function(input, gp)
if gp then return end
if not toolEquipped then return end
if mouse.Target == nil then return end
local function DetectInput(skillConfig, debounce)
if input.KeyCode == Enum.KeyCode[tostring(skillConfig:WaitForChild("Key").Value)] then
if toolEquipped then
if not debounce and canAttack.Value == true then
if level.Value >= skillConfig:WaitForChild("LevelRequired").Value then
print(debounce)
debounce = true
remote:FireServer(mouse.Hit.p, skillConfig.Name)
changeCanAttack:FireServer(false)
wait(skillConfig:WaitForChild("Duration").Value)
toolUI:WaitForChild(skillConfig.Name):WaitForChild("Cooldown").BackgroundTransparency = 0
ts:Create(toolUI:WaitForChild(skillConfig.Name):WaitForChild("Cooldown"), TweenInfo.new(skillConfig:WaitForChild("Cooldown").Value, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
changeCanAttack:FireServer(true)
debounce = true
wait(skillConfig:WaitForChild("Cooldown").Value)
debounce = false
else
warn("Couldn't do the attack. Please reach the required level ("..skillConfig:WaitForChild("LevelRequired").Value..") to perfom it.")
end
end
end
end
end
DetectInput(skillConfigs:WaitForChild("Fireball"), debounce1)
DetectInput(skillConfigs:WaitForChild("Fire Breath"), debounce2)
DetectInput(skillConfigs:WaitForChild("Blazing Barrier"), debounce3)
DetectInput(skillConfigs:WaitForChild("Fire Projectiles"), debounce4)
DetectInput(skillConfigs:WaitForChild("Nova Bomb"), debounce5)
end)
I believe the reason it is printing false is because you print it before you make it true.
uis.InputBegan:Connect(function(input, gp)
if gp then return end
if not toolEquipped then return end
if mouse.Target == nil then return end
local function DetectInput(skillConfig, debounce)
if input.KeyCode == Enum.KeyCode[tostring(skillConfig:WaitForChild("Key").Value)] then
if toolEquipped then
if not debounce and canAttack.Value == true then
if level.Value >= skillConfig:WaitForChild("LevelRequired").Value then
debounce = true
print(debounce)
remote:FireServer(mouse.Hit.p, skillConfig.Name)
changeCanAttack:FireServer(false)
wait(skillConfig:WaitForChild("Duration").Value)
toolUI:WaitForChild(skillConfig.Name):WaitForChild("Cooldown").BackgroundTransparency = 0
ts:Create(toolUI:WaitForChild(skillConfig.Name):WaitForChild("Cooldown"), TweenInfo.new(skillConfig:WaitForChild("Cooldown").Value, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
changeCanAttack:FireServer(true)
wait(skillConfig:WaitForChild("Cooldown").Value)
debounce = false
else
warn("Couldn't do the attack. Please reach the required level ("..skillConfig:WaitForChild("LevelRequired").Value..") to perfom it.")
end
end
end
end
end
DetectInput(skillConfigs:WaitForChild("Fireball"), debounce1)
DetectInput(skillConfigs:WaitForChild("Fire Breath"), debounce2)
DetectInput(skillConfigs:WaitForChild("Blazing Barrier"), debounce3)
DetectInput(skillConfigs:WaitForChild("Fire Projectiles"), debounce4)
DetectInput(skillConfigs:WaitForChild("Nova Bomb"), debounce5)
end)
i think i know what is causing the issue, you are basically re-creating the function every time you activate it, your function should be created before the main script.
local function DetectInput(skillConfig, debounce)
if input.KeyCode == Enum.KeyCode[tostring(skillConfig:WaitForChild("Key").Value)] then
if toolEquipped then
if not debounce and canAttack.Value == true then
if level.Value >= skillConfig:WaitForChild("LevelRequired").Value then
print(debounce)
debounce = true
remote:FireServer(mouse.Hit.p, skillConfig.Name)
changeCanAttack:FireServer(false)
wait(skillConfig:WaitForChild("Duration").Value)
toolUI:WaitForChild(skillConfig.Name):WaitForChild("Cooldown").BackgroundTransparency = 0
ts:Create(toolUI:WaitForChild(skillConfig.Name):WaitForChild("Cooldown"), TweenInfo.new(skillConfig:WaitForChild("Cooldown").Value, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
changeCanAttack:FireServer(true)
debounce = true
wait(skillConfig:WaitForChild("Cooldown").Value)
debounce = false
else
warn("Couldn't do the attack. Please reach the required level ("..skillConfig:WaitForChild("LevelRequired").Value..") to perfom it.")
end
end
end
end
end
uis.InputBegan:Connect(function(input, gp)
if gp then return end
if not toolEquipped then return end
if mouse.Target == nil then return end
DetectInput(skillConfigs:WaitForChild("Fireball"), false)
DetectInput(skillConfigs:WaitForChild("Fire Breath"), false)
DetectInput(skillConfigs:WaitForChild("Blazing Barrier"), false)
DetectInput(skillConfigs:WaitForChild("Fire Projectiles"), false)
DetectInput(skillConfigs:WaitForChild("Nova Bomb"), false)
end)