Hey! I am currently working on a project and I have a module script that holds each fighters animations. Though, there’s a big issue… the animation does not stop playing. I have literally been trying to fix this for the past week but I have not been able to figure it out, the animation plays just fine but it wont stop at all. Here is the Module code:
local AnimationHandler = {}
--//[SERVICES]//--
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--//[VARIABLES]//--
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoind = Character:FindFirstChild("Humanoid")
local AnimationInstance = Instance.new("Animation")
local animationHolder = {
-- holds the animations for each character --
["BetaCharacter"] = {
RunningAnimation = "rbxassetid://18893805284",
}
}
--//[FUNCTIONS]//--
function AnimationHandler:animateBetaCharacter(animationType, loopAnimation, stopAnimation)
AnimationInstance.AnimationId = animationHolder.BetaCharacter[animationType]
local AnimationTrack = Humanoind:WaitForChild("Animator"):LoadAnimation(AnimationInstance)
if stopAnimation then
AnimationTrack:Stop()
else
AnimationTrack:Play()
end
if loopAnimation then
AnimationTrack.Looped = true
else
warn("Animation not looped")
AnimationTrack.Looped = false
end
end
return AnimationHandler
Here is the local script that calls the module script:
--{BetaCharacter Moveset}--
--//[SERVICES]//--
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
--//[MODULES]//--
local AnimationModule = require(RepStorage.ClientModules.AnimationModule)
--//[EVENTS]//--
--//[VARIABLES]//--
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
local Mouse = Player:GetMouse()
local LastTime = tick() -- The last time you clicked the sprint key button
local DoubleTapTime = 0.8 -- How long you have to click the sprint key before the time resets for the double tap to sprint
local characterStats = {
-- holds all the stats for the character
-- MOVEMENT STATS --
["Running Stats"] = {
RunningSpeed = 25,
DefaultSpeed = 16
};
}
local keyBinds = {
-- holds all the default keybinds for each move
-- Attacks --
Attack1Key = Enum.KeyCode.One,
Attack2Key = Enum.KeyCode.Two,
Attack3Key = Enum.KeyCode.Three,
Attack4Key = Enum.KeyCode.Four,
CounterKey = Enum.KeyCode.Five,
BlockKey = Enum.KeyCode.F,
UltimateKey = Enum.KeyCode.G,
-- Movement --
SprintKey = Enum.KeyCode.W,
DashKey = Enum.KeyCode.Q
}
--//[FUNCTIONS]//--
local function onFighterRunning(input, gameProccessedEvent)
if gameProccessedEvent then return end
if input.KeyCode == keyBinds.SprintKey then
local Difference = tick() - LastTime -- if the getting the number difference
if Difference <= DoubleTapTime then -- if the time it took you to press W again is less than the doubletaptime then you can run!
AnimationModule:animateBetaCharacter("RunningAnimation")
Humanoid.WalkSpeed = characterStats["Running Stats"].RunningSpeed -- setting the walkspeed to the correct speed for the character stats
end
LastTime = tick()
end
end
local function onFighterStopRunning(input)
if input.KeyCode == keyBinds.SprintKey then
AnimationModule:animateBetaCharacter("RunningAnimation", true)
Humanoid.WalkSpeed = characterStats["Running Stats"].DefaultSpeed
end
end
--//[SIGNALS]//--
UIS.InputBegan:Connect(onFighterRunning) -- sprinting signals
UIS.InputEnded:Connect(onFighterStopRunning) -- sprinting signals
-------------------------------------------------------------------
Any help would be great! Thanks!!