You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want my block debounce to actually work.
What is the issue? Include screenshots / videos if possible!
Whenever you hold block it kinda doesn’t work
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, I have, they didn’t help.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Script:
- Removed to prevent stealing of code
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.
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local IsBlocking = Character:WaitForChild("Information").Blocking.Value
local BlockAnimation = Character.Humanoid.Animator:LoadAnimation(script:WaitForChild("Block"))
local debounce = false
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F and debounce ~= true then
BlockAnimation:Play()
game.ReplicatedStorage.Blocking:FireServer("On")
end
end)
UIS.InputEnded:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F and debounce ~= true then
debounce = true
BlockAnimation:Stop()
game.ReplicatedStorage.Blocking:FireServer("Off")
task.wait(2.5)
debounce = false
end
end)
I would actually just move the debounce up to right after you check if its false:
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local IsBlocking = Character:WaitForChild("Information").Blocking.Value
local BlockAnimation = Character.Humanoid.Animator:LoadAnimation(script:WaitForChild("Block"))
local debounce = false
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F and debounce == false then
debounce = true
BlockAnimation:Play()
game.ReplicatedStorage.Blocking:FireServer("On")
end
end)
UIS.InputEnded:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F then
BlockAnimation:Stop()
game.ReplicatedStorage.Blocking:FireServer("Off")
wait(2.5)
debounce = false
end
end)
check for debounce in input ended connection and it should behave as expected
UIS.InputEnded:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F and not debounce then
debounce = true
BlockAnimation:Stop()
game.ReplicatedStorage.Blocking:FireServer("Off")
wait(2.5)
debounce = false
end
end)
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local IsBlocking = Character:WaitForChild("Information").Blocking.Value
local BlockAnimation = Character.Humanoid.Animator:LoadAnimation(script:WaitForChild("Block"))
local debounce = false
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F and not debounce then
BlockAnimation:Play()
game.ReplicatedStorage.Blocking:FireServer("On")
end
end)
UIS.InputEnded:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.F and not debounce then
debounce = true
BlockAnimation:Stop()
game.ReplicatedStorage.Blocking:FireServer("Off")
wait(2.5)
debounce = false
end
end)
local debounce = false
some_function_definition(some_parameters)
if not debounce then
debounce = true
-- Do Something
delay(timeout, function()
debounce = false
end)
end
end
The delay function spawns a new thread that doesn’t start executing the nested function until the timeout has elapsed. This is the preferred way because it doesn’t hang up the thread context that the some_function is executing in.
Although this is being executed on the client, you should also have similar code on the server to prevent abuse by exploiters.