I’m making an animation module for my platformer game, it looks pretty messy to me, and I’m also not sure if this will even work or not.
Here is the local script
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local module = require(game:GetService("ReplicatedStorage"):WaitForChild("Player"):WaitForChild("AnimationModule"))
game:GetService("RunService").Heartbeat:Connect(function()
if humanoid.WalkSpeed > 0 and not module.stateLock then
module.state = "sprinting"
module.animations.sprinting:Play()
elseif humanoid.WalkSpeed == 0 and not module.stateLock then
module.animations.idle:Play()
end
end)
Module Script
local module = {}
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
module.state = "NaN"
module.stateLock = false
Instance.new("Animation", script).Name = "idle"
Instance.new("Animation", script).Name = "sprinting"
Instance.new("Animation", script).Name = "jumping"
Instance.new("Animation", script).Name = "climbing"
Instance.new("Animation", script).Name = "swimming"
Instance.new("Animation", script).Name = "longJump"
Instance.new("Animation", script).Name = "crouch"
Instance.new("Animation", script).Name = "dive"
Instance.new("Animation", script).Name = "groundPound"
script:WaitForChild("idle").AnimationId = "rbxassetid://1"
script:WaitForChild("sprinting").AnimationId = "rbxassetid://1"
script:WaitForChild("jumping").AnimationId = "rbxassetid://1"
script:WaitForChild("climbing").AnimationId = "rbxassetid://1"
script:WaitForChild("swimming").AnimationId = "rbxassetid://1"
script:WaitForChild("longJump").AnimationId = "rbxassetid://1"
script:WaitForChild("crouch").AnimationId = "rbxassetid://1"
script:WaitForChild("dive").AnimationId = "rbxassetid://1"
script:WaitForChild("groundPound").AnimationId = "rbxassetid://1"
module.animations = {
-- Core Animations
idle = humanoid:LoadAnimation(script:WaitForChild("idle"));
sprinting = humanoid:LoadAnimation(script:WaitForChild("sprinting"));
jumping = humanoid:LoadAnimation(script:WaitForChild("jumping"));
climbing = humanoid:LoadAnimation(script:WaitForChild("climbing"));
swimming = humanoid:LoadAnimation(script:WaitForChild("swimming"));
-- Moveset Animations
longJump = humanoid:LoadAnimation(script:WaitForChild("longJump"));
crouch = humanoid:LoadAnimation(script:WaitForChild("crouch"));
dive = humanoid:LoadAnimation(script:WaitForChild("dive"));
groundPound = humanoid:LoadAnimation(script:WaitForChild("groundPound"));
}
function forceAnimation(animation)
for i, v in pairs(module.animations) do
if v.Name ~= animation then
if v.IsPlaying then
v:Stop()
end
end
end
animation:Play()
end
return module