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.
How exactly would I replace the debounce turning to true or checking if the debounce was true?
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.
Server-Side debounce:
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)
Okay, I will try out this script and see if it works.
It still sometimes does the cooldown twice if you spam ‘F’
Did you put a delay/cooldown in the event function?
You haven’t made the blockdebounce true below it.
I tried that and I couldn’t unblock.
here
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)
Key should not be == F, rather. Key == Enum.KeyCode.F
Have you tried a debounce on both the Server-Side and Client-Side?
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)
there should fix it
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 …
That could be the issue… we are unaware…
Merely posting and helping where I can.
Well, the code Michael posted seems to work and there seems to be nothing wrong with the client script.
The code you posted didn’t work.
It seems like it’s fixed, but I’m not 100% sure, I’ll test it with some things and reply to you whether or not it still works, I’ll also mark your message as a solution for now.
Thank you so much! I tested it with other players to make sure nothing broke, it works perfectly!