The following is a code snippet of part of my moveset script in starterplayerscripts using CAS.
function activateMove(action, inputState, character)
-- Cooldown check
local cooldown = cooldownList[character][action]
if cooldown.debounce and inputState == Enum.UserInputState.Begin and not cooldownList[character].active then
-- Call move and start cooldown
cooldown.debounce = false
cooldownList[character].active = true
game.ReplicatedStorage.CharacterRemoteEvents:FindFirstChild(character):FindFirstChild(action):FireServer(cooldown.length)
print(character.. " ".. action)
wait(cooldown.length)
cooldown.debounce = true
cooldownList[character].active = false
end
end
I have also made a separate script that resets the player’s cooldowns upon death using CharacterAdded. This works: the problem is that when the player dies while using a move, the above function is still running. This means that they can use the move again, then the function call from before they died will reset the cooldown, allowing them to use the move again early.
How can I prevent this? As in, make it so the function just stops on death?
NOTE: For reasons, I cannot use startercharacterscripts.
NOTE2: I tried using a “died” boolean variable with the character added script, but because character added also counts for the first spawn, it ends up not working as the cooldowns are never reset. If this gives an idea that you think may work, do share.