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 it so that the cooldown on block only happens one time.
What is the issue? Include screenshots / videos if possible!
If you spam ‘F’ on your keyboard sometimes the cooldown happens two times instead of once.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, I haven’t found a solution to my problem on devforum.
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!
This is the server script:
local KeyEvent = game.ReplicatedStorage.KeyBindEvent
local blockdebounce = false
local IsBlocking = character:WaitForChild("Data").IsBlocking.Value
local BlockAnimation = character.Humanoid.Animator:LoadAnimation(game.ServerStorage.CharacterAnims.Test)
local KeyEndedEvent = game.ReplicatedStorage.KeyEndedEvent
KeyEvent.OnServerEvent:Connect(function(plr, key, IsTyping)
if IsTyping then return end
if key == "F" and not blockdebounce then
BlockAnimation:Play()
character:WaitForChild("BlockingEffects").Trail3.Enabled = true
character:WaitForChild("Data").CantMove.Value = true
character:WaitForChild("Data").IsBlocking.Value = true
character.Data:WaitForChild("BlockingEffects").Trail.Enabled = true
character.Data:WaitForChild("BlockingEffects").Trail1.Enabled = true
end
end)
KeyEndedEvent.OnServerEvent:Connect(function(plr, key, IsTyping)
if IsTyping then return end
if key == "F" and not blockdebounce then
blockdebounce = true
BlockAnimation:Stop()
character:WaitForChild("Data").CantMove.Value = false
character:WaitForChild("Data").IsBlocking.Value = false
character.Data:WaitForChild("BlockingEffects").Trail3.Enabled = false
character.Data:WaitForChild("BlockingEffects").Trail.Enabled = false
character.Data:WaitForChild("BlockingEffects").Trail1.Enabled = false
wait(0.75)
blockdebounce = false
end
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.
I’m a bit confused about how this code even works sometimes as it is. The way I see it you press “F”, the debounce is set to true and then key ended won’t run?
My thoughts on what is going wrong are that you don’t currently check if the player is blocking during the key ended function. If you added that check I reckon you would fix the issue.
that’s why sometimes i add two debounce, The debounce at the start of the function, and another one when the command runs, hardly the client will bypass two debounce, only if your coding is really weird somehow
Nothing, it just fires a remote event when a key is pressed and sends over what key was pressed, the server then checks what key it is and if it’s F then it blocks, In this case I’m only using the client to send information to the server, that’s it.
An alternative to using debounces is to use a timestamp instead. E.g. your key press function would check that os.time() - timestamp > 0.75 and the key ended function would update the timestamp to the current time.
Looking at your code as posted the blockdebounce is global to all functions. So when the function KeyEvent. turned it true … it was also true when it got to the KeyEndedEvent. function.
local debounce = {}
someRemote.OnServerEvent:Connect(function(player,...)
if not table.find(debounce,player) then
table.insert(debounce,player)
--code here
--when done:
table.remove(debounce,table.find(debounce,player))
end
end)
local KeyEvent = game.ReplicatedStorage.KeyBindEvent
local blockdebounce = false
local blockdebounce2 = false
local IsBlocking = character:WaitForChild("Data").IsBlocking.Value
local BlockAnimation = character.Humanoid.Animator:LoadAnimation(game.ServerStorage.CharacterAnims.Test)
local KeyEndedEvent = game.ReplicatedStorage.KeyEndedEvent
KeyEvent.OnServerEvent:Connect(function(plr, key, IsTyping)
if IsTyping then return end
if key == "F" and not blockdebounce and not blockdebounce2 then
blockdebounce2 = true
BlockAnimation:Play()
character:WaitForChild("BlockingEffects").Trail3.Enabled = true
character:WaitForChild("Data").CantMove.Value = true
character:WaitForChild("Data").IsBlocking.Value = true
character.Data:WaitForChild("BlockingEffects").Trail.Enabled = true
character.Data:WaitForChild("BlockingEffects").Trail1.Enabled = true
end
end)
KeyEndedEvent.OnServerEvent:Connect(function(plr, key, IsTyping)
if IsTyping then return end
if key == "F" and not blockdebounce and blockdebounce2 then
blockdebounce = true
blockdebounce2 = false
BlockAnimation:Stop()
character:WaitForChild("Data").CantMove.Value = false
character:WaitForChild("Data").IsBlocking.Value = false
character.Data:WaitForChild("BlockingEffects").Trail3.Enabled = false
character.Data:WaitForChild("BlockingEffects").Trail.Enabled = false
character.Data:WaitForChild("BlockingEffects").Trail1.Enabled = false
wait(0.75)
blockdebounce = false
end
end)
local KeyEvent = game.ReplicatedStorage.KeyBindEvent
local blockdebounce = false
local IsBlocking = character:WaitForChild("Data").IsBlocking.Value
local BlockAnimation = character.Humanoid.Animator:LoadAnimation(game.ServerStorage.CharacterAnims.Test)
local KeyEndedEvent = game.ReplicatedStorage.KeyEndedEvent
KeyEvent.OnServerEvent:Connect(function(plr, key, IsTyping)
if IsTyping then return end
if key == "F" and not blockdebounce then
blockdebounce = true
BlockAnimation:Play()
character:WaitForChild("BlockingEffects").Trail3.Enabled = true
character:WaitForChild("Data").CantMove.Value = true
character:WaitForChild("Data").IsBlocking.Value = true
character.Data:WaitForChild("BlockingEffects").Trail.Enabled = true
character.Data:WaitForChild("BlockingEffects").Trail1.Enabled = true
end
end)
KeyEndedEvent.OnServerEvent:Connect(function(plr, key, IsTyping)
if IsTyping then return end
if key == "F" and blockdebounce then
blockdebounce = true
BlockAnimation:Stop()
character:WaitForChild("Data").CantMove.Value = false
character:WaitForChild("Data").IsBlocking.Value = false
character.Data:WaitForChild("BlockingEffects").Trail3.Enabled = false
character.Data:WaitForChild("BlockingEffects").Trail.Enabled = false
character.Data:WaitForChild("BlockingEffects").Trail1.Enabled = false
wait(0.75)
blockdebounce = false
end
end)
We are not looking at the whole code here as posted it don’t even work. He must be passing the key value but who knows … I pointed out a clear logic error and got no response back …