Advertisement
Anukun_Lucifer

Animations (EP07)

Nov 25th, 2023
2,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | Gaming | 0 0
  1. local replicatedstorage = game:GetService("ReplicatedStorage")
  2.  
  3. local event = replicatedstorage:WaitForChild("Events")
  4. local animatetowerevent = event:WaitForChild("AnimateTower")
  5.  
  6. local function setAnimation(object, animName)
  7.     local humanoid = object:WaitForChild("Humanoid")
  8.     local animationsfolder = object:WaitForChild("Animations")
  9.    
  10.     if humanoid and animationsfolder then
  11.         local animationsobject = animationsfolder:WaitForChild(animName)
  12.        
  13.         if animationsobject then
  14.             local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator",humanoid)
  15.            
  16.             local playingTracks = animator:GetPlayingAnimationTracks()
  17.             for i, track in pairs(playingTracks) do
  18.                 if track.Name == animName then
  19.                     return track
  20.                 end
  21.             end
  22.            
  23.             local animationstrack = animator:LoadAnimation(animationsobject)
  24.             return animationstrack
  25.         end
  26.     end
  27. end
  28.  
  29. local function playAnimation(object, animName)
  30.     local animationstrack = setAnimation(object ,animName)
  31.    
  32.     if animationstrack then
  33.         animationstrack:Play()
  34.     else
  35.         warn("Animation track dose not exist")
  36.         return
  37.     end
  38. end
  39.  
  40. workspace.Grassland.Mob.ChildAdded:Connect(function(object)
  41.     playAnimation(object, "Walk")
  42. end)
  43.  
  44. workspace.Grassland.Tower.ChildAdded:Connect(function(object)
  45.     playAnimation(object, "Idel")
  46. end)
  47.  
  48. animatetowerevent.OnClientEvent:Connect(function(tower, animName)
  49.     playAnimation(tower, animName)
  50. end)
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement