Advertisement
Familycade

Untitled

Nov 23rd, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. local replacementAnimations = {
  2. ["Punch"] = "rbxassetid://14705929107", -- First move: Punch
  3. ["Run"] = "rbxassetid://14003607057", -- Second move: Run
  4. }
  5.  
  6. local function onAnimationPlayed(animationTrack)
  7. if player.Character and humanoid then
  8. -- Extract the animation ID
  9. local animationId = animationTrack.Animation.AnimationId:match("%d+")
  10.  
  11. -- Match animation ID with the mapped names
  12. for moveName, replacementId in pairs(replacementAnimations) do
  13. local originalId = replacementId:match("%d+") -- Extract replacement ID for comparison
  14. if animationId == originalId then
  15. animationTrack:Stop()
  16.  
  17. -- Create and play the replacement animation
  18. local newAnimation = Instance.new("Animation")
  19. newAnimation.AnimationId = "rbxassetid://" .. animationId
  20. local newTrack = humanoid:LoadAnimation(newAnimation)
  21. newTrack:Play()
  22.  
  23. print("Played move:", moveName) -- Log the move for debugging
  24. return
  25. end
  26. end
  27. end
  28. end
  29.  
  30. local function setupCharacter(newCharacter)
  31. character = newCharacter
  32. humanoid = newCharacter:WaitForChild("Humanoid")
  33.  
  34. -- Disconnect existing connections to avoid duplication
  35. if humanoidConnection then
  36. humanoidConnection:Disconnect()
  37. end
  38.  
  39. humanoidConnection = humanoid.AnimationPlayed:Connect(onAnimationPlayed)
  40. end
  41.  
  42. player.CharacterAdded:Connect(setupCharacter)
  43.  
  44. -- Ensure the script sets up the character if it already exists
  45. if player.Character then
  46. setupCharacter(player.Character)
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement