#Animation Core not working. How to fix with a script?

4 messages · Page 1 of 1 (latest)

tired flax
#

any idea how to solve this issue over here. The M3,M4 are punching sideways, like its following the animation of the idle and not the punching...

lone orchid
#

.

tired flax
#

@lone orchid ```lua
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FistsFolder = ReplicatedStorage.Fists
local AnimationsFolder = FistsFolder.Animations

-- Animation setup
local animations = {
AnimationsFolder.M1,
AnimationsFolder.M2,
AnimationsFolder.M3,
AnimationsFolder.M4,
AnimationsFolder.M5
}
local idleAnimation = AnimationsFolder.Idle
local specificToolName = "FistsTool"

-- Player setup
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")

-- Animation control variables
local currentAnimationIndex = 1
local currentAnimTrack = nil
local canPlayNextAnimation = true
local idleAnimTrack = nil

-- Connection variables
local inputBeganConnection = nil
local markerReachedConnection = nil

-- Play the next animation
local function playNextAnimation()
if not canPlayNextAnimation then return end

if currentAnimTrack then
    currentAnimTrack:Stop()
    if markerReachedConnection then
        markerReachedConnection:Disconnect()
    end
end

currentAnimTrack = humanoid:LoadAnimation(animations[currentAnimationIndex])
currentAnimTrack:Play()

markerReachedConnection = currentAnimTrack:GetMarkerReachedSignal("DBReset"):Connect(function()
    canPlayNextAnimation = true
end)

currentAnimationIndex = (currentAnimationIndex % #animations) + 1
canPlayNextAnimation = false

end

-- Handle tool equipped
local function onToolEquipped(NewChild)
if NewChild:IsA("Tool") and NewChild.Name == specificToolName then
if idleAnimTrack then
idleAnimTrack:Stop()
end
idleAnimTrack = humanoid:LoadAnimation(idleAnimation)
idleAnimTrack:Play()

    inputBeganConnection = UserInputService.InputBegan:Connect(function(InputObject)
        if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
            playNextAnimation()
        end
    end)
end

end

-- Handle tool unequipped
local function onToolUnequipped(RemovedChild)
if RemovedChild:IsA("Tool") and RemovedChild.Name == specificToolName then
if idleAnimTrack and idleAnimTrack.IsPlaying then
idleAnimTrack:Stop()
end

    if inputBeganConnection then
        inputBeganConnection:Disconnect()
        inputBeganConnection = nil
    end

    if markerReachedConnection then
        markerReachedConnection:Disconnect()
    end
end

end

-- Check and play idle animation based on player speed
local function checkAndPlayIdleAnimation(speed)
if speed == 0 and Character:FindFirstChild(specificToolName) then
if not idleAnimTrack or not idleAnimTrack.IsPlaying then
idleAnimTrack = humanoid:LoadAnimation(idleAnimation)
idleAnimTrack:Play()
end
else
if idleAnimTrack and idleAnimTrack.IsPlaying then
idleAnimTrack:Stop()
end
end
end

-- Event connections
Character.ChildAdded:Connect(onToolEquipped)
Character.ChildRemoved:Connect(onToolUnequipped)
humanoid.Running:Connect(checkAndPlayIdleAnimation)