daily pastebin goal
33%
SHARE
TWEET

Untitled

daaa Jun 19th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Made by Luckymaxer
  2.  
  3. Tool = script.Parent
  4. Handle = Tool:WaitForChild("Handle")
  5.  
  6. Players = game:GetService("Players")
  7. RunService = game:GetService("RunService")
  8. ContentProvider = game:GetService("ContentProvider")
  9.  
  10. RbxUtility = LoadLibrary("RbxUtility")
  11. Create = RbxUtility.Create
  12.  
  13. Animations = {}
  14.  
  15. ServerControl = Tool:WaitForChild("ServerControl")
  16. ClientControl = Tool:WaitForChild("ClientControl")
  17.  
  18. Rate = (1 / 60)
  19.  
  20. ToolEquipped = false
  21.  
  22. function SetAnimation(mode, value)
  23.     if not ToolEquipped or not CheckIfAlive() then
  24.         return
  25.     end
  26.     local function StopAnimation(Animation)
  27.         for i, v in pairs(Animations) do
  28.             if v.Animation == Animation then
  29.                 v.AnimationTrack:Stop(value.EndFadeTime)
  30.                 if v.TrackStopped then
  31.                     v.TrackStopped:disconnect()
  32.                 end
  33.                 table.remove(Animations, i)
  34.             end
  35.         end
  36.     end
  37.     if mode == "PlayAnimation" then
  38.         for i, v in pairs(Animations) do
  39.             if v.Animation == value.Animation then
  40.                 if value.Speed then
  41.                     v.AnimationTrack:AdjustSpeed(value.Speed)
  42.                     return
  43.                 elseif value.Weight or value.FadeTime then
  44.                     v.AnimationTrack:AdjustWeight(value.Weight, value.FadeTime)
  45.                     return
  46.                 else
  47.                     StopAnimation(value.Animation, false)
  48.                 end
  49.             end
  50.         end
  51.         local AnimationMonitor = Create("Model"){}
  52.         local TrackEnded = Create("StringValue"){Name = "Ended"}
  53.         local AnimationTrack = Humanoid:LoadAnimation(value.Animation)
  54.         local TrackStopped
  55.         if not value.Manual then
  56.             TrackStopped = AnimationTrack.Stopped:connect(function()
  57.                 if TrackStopped then
  58.                     TrackStopped:disconnect()
  59.                 end
  60.                 StopAnimation(value.Animation, true)
  61.                 TrackEnded.Parent = AnimationMonitor
  62.             end)
  63.         end
  64.         table.insert(Animations, {Animation = value.Animation, AnimationTrack = AnimationTrack, TrackStopped = TrackStopped})
  65.         AnimationTrack:Play(value.FadeTime, value.Weight, value.Speed)
  66.         if TrackStopped then
  67.             AnimationMonitor:WaitForChild(TrackEnded.Name)
  68.         end
  69.         return TrackEnded.Name
  70.     elseif mode == "StopAnimation" and value then
  71.         StopAnimation(value.Animation)
  72.     end
  73. end
  74.  
  75. function CheckIfAlive()
  76.     return (((Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Player and Player.Parent) and true) or false)
  77. end
  78.  
  79. function Equipped(Mouse)
  80.     Character = Tool.Parent
  81.     Player = Players:GetPlayerFromCharacter(Character)
  82.     Humanoid = Character:FindFirstChild("Humanoid")
  83.     ToolEquipped = true
  84.     if not CheckIfAlive() then
  85.         return
  86.     end
  87.     Spawn(function()
  88.         PlayerMouse = Player:GetMouse()
  89.         Mouse.Button1Down:connect(function()
  90.             InvokeServer("Button1Click", {Down = true})
  91.         end)
  92.         Mouse.Button1Up:connect(function()
  93.             InvokeServer("Button1Click", {Down = false})
  94.         end)
  95.         Mouse.KeyDown:connect(function(Key)
  96.             InvokeServer("KeyPress", {Key = Key, Down = true})
  97.         end)
  98.         Mouse.KeyUp:connect(function(Key)
  99.             InvokeServer("KeyPress", {Key = Key, Down = false})
  100.         end)
  101.         for i, v in pairs(Tool:GetChildren()) do
  102.             if v:IsA("Animation") then
  103.                 ContentProvider:Preload(v.AnimationId)
  104.             end
  105.         end
  106.     end)
  107. end
  108.  
  109. function Unequipped()
  110.     for i, v in pairs(Animations) do
  111.         if v and v.AnimationTrack then
  112.             v.AnimationTrack:Stop()
  113.         end
  114.     end
  115.     Animations = {}
  116.     ToolEquipped = false
  117. end
  118.  
  119. function InvokeServer(mode, value)
  120.     local ServerReturn = nil
  121.     pcall(function()
  122.         ServerReturn = ServerControl:InvokeServer(mode, value)
  123.     end)
  124.     return ServerReturn
  125. end
  126.  
  127. function OnClientInvoke(mode, value)
  128.     if mode == "PlayAnimation" and value and ToolEquipped and Humanoid then
  129.         SetAnimation("PlayAnimation", value)
  130.     elseif mode == "StopAnimation" and value then
  131.         SetAnimation("StopAnimation", value)
  132.     elseif mode == "PlaySound" and value then
  133.         value:Play()
  134.     elseif mode == "StopSound" and value then
  135.         value:Stop()
  136.     elseif mode == "MousePosition" then
  137.         return {Position = PlayerMouse.Hit.p, Target = PlayerMouse.Target}
  138.     end
  139. end
  140.  
  141. ClientControl.OnClientInvoke = OnClientInvoke
  142. Tool.Equipped:connect(Equipped)
  143. Tool.Unequipped:connect(Unequipped)
RAW Paste Data
Top