Advertisement
Anukun_Lucifer

Animations

Nov 19th, 2023
2,510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 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.             local animationstrack = animator:LoadAnimation(animationsobject)
  16.             return animationstrack
  17.         end
  18.     end
  19. end
  20.  
  21. local function playAnimation(object, animName)
  22.     local animationstrack = setAnimation(object ,animName)
  23.    
  24.     if animationstrack then
  25.         animationstrack:Play()
  26.     else
  27.         warn("Animation track dose not exist")
  28.         return
  29.     end
  30. end
  31.  
  32. workspace.Grassland.Mob.ChildAdded:Connect(function(object)
  33.     playAnimation(object, "Walk")
  34. end)
  35.  
  36. workspace.Grassland.Tower.ChildAdded:Connect(function(object)
  37.     playAnimation(object, "Idel")
  38. end)
  39.  
  40. animatetowerevent.OnClientEvent:Connect(function(tower, animName)
  41.     playAnimation(tower, animName)
  42. end)
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement