Hello guys i making a medieval open world game. Its now time to make anims play and i wrote this script. The thing is none of anims in the code below are working rn so i need your help.
Anims are loaded in ‘Animation’ objects they are in folder which is in tool which is in replicatedstorage. So the way they should work:
Onback - axe tool in inventory, not equipped
equip - tool equipping anim
walk - tool already equipped, not activated, and player is walking
idle - tool already equipped, not activated, and player is idle/afk
any help aprecciated
code below
```local tool = script.Parent
local player = game.Players.LocalPlayer
if not player then return end
local Humanoid = nil
local equip = nil
local idle = nil
local walk = nil
local Onback = nil
local function loadAnimations()
local character = player.Character
if not character then return end
Humanoid = character:WaitForChild("Humanoid")
if Humanoid then
local animationsFolder = tool.Animations
if animationsFolder then
equip = Humanoid:LoadAnimation(animationsFolder:FindFirstChild("Axe_Equip"))
idle = Humanoid:LoadAnimation(animationsFolder:FindFirstChild("Axe_Equip_Idle"))
walk = Humanoid:LoadAnimation(animationsFolder:FindFirstChild("Axe_Equip_Walk"))
Onback = Humanoid:LoadAnimation(animationsFolder:FindFirstChild("Axe_OnBack & Reference"))
else
warn("Animations folder not found!")
end
end
end
local function playEquipAnimation()
if Humanoid and Humanoid.Health > 0 and Humanoid.RigType == Enum.HumanoidRigType.R15 then
if equip then
Onback:Stop()
equip:Play()
equip.Stopped:Connect(function()
idle:Play()
end)
end
end
end
local function stopAnimations()
if idle then idle:Stop() end
if walk then walk:Stop() end
if Onback then Onback:Play() end
end
player.CharacterAdded:Connect(function(character)
Humanoid = character:WaitForChild("Humanoid")
loadAnimations()
tool.Equipped:Connect(playEquipAnimation)
tool.Unequipped:Connect(stopAnimations)
local currentAnimation = idle -- Начальная анимация - idle
Humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Running or newState == Enum.HumanoidStateType.Jumping then
if currentAnimation ~= walk then
idle:Stop()
walk:Play()
currentAnimation = walk
end
elseif oldState == Enum.HumanoidStateType.Running or oldState == Enum.HumanoidStateType.Jumping then
if currentAnimation ~= idle then
walk:Stop()
idle:Play()
currentAnimation = idle
end
end
end)
end)