Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local replacementAnimations = {
- ["Punch"] = "rbxassetid://14705929107", -- First move: Punch
- ["Run"] = "rbxassetid://14003607057", -- Second move: Run
- }
- local function onAnimationPlayed(animationTrack)
- if player.Character and humanoid then
- -- Extract the animation ID
- local animationId = animationTrack.Animation.AnimationId:match("%d+")
- -- Match animation ID with the mapped names
- for moveName, replacementId in pairs(replacementAnimations) do
- local originalId = replacementId:match("%d+") -- Extract replacement ID for comparison
- if animationId == originalId then
- animationTrack:Stop()
- -- Create and play the replacement animation
- local newAnimation = Instance.new("Animation")
- newAnimation.AnimationId = "rbxassetid://" .. animationId
- local newTrack = humanoid:LoadAnimation(newAnimation)
- newTrack:Play()
- print("Played move:", moveName) -- Log the move for debugging
- return
- end
- end
- end
- end
- local function setupCharacter(newCharacter)
- character = newCharacter
- humanoid = newCharacter:WaitForChild("Humanoid")
- -- Disconnect existing connections to avoid duplication
- if humanoidConnection then
- humanoidConnection:Disconnect()
- end
- humanoidConnection = humanoid.AnimationPlayed:Connect(onAnimationPlayed)
- end
- player.CharacterAdded:Connect(setupCharacter)
- -- Ensure the script sets up the character if it already exists
- if player.Character then
- setupCharacter(player.Character)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement