Er1x_Official

Script, Barrage Tutorial

Sep 12th, 2021 (edited)
4,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.60 KB | None | 0 0
  1. -- script
  2. -- variables
  3. local tool = script.Parent
  4. local the
  5. local f = false
  6. local playing = false
  7. local tween = game:GetService("TweenService")
  8. local debris = game:GetService("Debris")
  9. local tookdmg = false
  10. local root
  11.  
  12. -- some important functions
  13. function Raycast(position, direction, range, ignore) -- raycast
  14.     local raycastParams = RaycastParams.new()
  15.     raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
  16.     raycastParams.FilterDescendantsInstances = {ignore}
  17.     raycastParams.IgnoreWater = false
  18.  
  19.     return workspace:Raycast(position, direction.unit * range, raycastParams)
  20. end
  21.  
  22. function ProperRaycast(StartPos, EndPos, Distance, Ignore) -- a proper raycast for the raycast (casting it properly)
  23.     local direction = CFrame.new(StartPos,EndPos).lookVector
  24.     return Raycast(StartPos, direction, Distance, Ignore)
  25. end
  26.  
  27. function createSound(parent,asset,volume,looped,name) -- creating a sound (audio efx)
  28.     local sound = Instance.new("Sound",parent)
  29.     sound.Name = name or "created sound effect"
  30.     sound.Looped = looped
  31.     sound.SoundId = asset
  32.     sound.Volume = volume
  33.     sound:Play()
  34.  
  35.     debris:AddItem(sound,sound.TimeLength)
  36. end
  37.  
  38. -- main functions
  39. script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,mouse) -- this will trigger when the remote event gets fired
  40.     if root ~= nil then
  41.         if f then          
  42.             local ray = ProperRaycast(root.Position,mouse.p,6,root.Parent) -- the '6' is the range
  43.             if ray then
  44.                 local hit = ray.Instance
  45.                 local hum = hit.Parent:FindFirstChildOfClass("Humanoid") -- finding the humanoid within the range
  46.                 if hum and tookdmg == false then
  47.                     tookdmg = true -- debounce
  48.                     hum:TakeDamage(1) -- taking damage
  49.                     createSound(hum.Parent:WaitForChild("HumanoidRootPart"),"rbxassetid://1720389178",math.random(0.1,1),false,"punch fx") -- the audio effect
  50.                     task.wait(0.1);tookdmg = false -- debounce
  51.                 end
  52.             end
  53.         end
  54.     end
  55. end)
  56.  
  57. tool.Activated:Connect(function() --- this gets triggered when you click the tool while equipped
  58.     if f == false then -- check if you are already attacking
  59.         local char = tool.Parent -- get the character of the player using the tool (YOU)
  60.         char.HumanoidRootPart.Anchored = true -- anchor the humanoid
  61.         local anim_start = script.Start -- get the animation
  62.         createSound(root,"rbxassetid://565208983",1,false,"rage fx")
  63.         char.Humanoid.Animator:LoadAnimation(anim_start):Play();task.wait(0.5)
  64.        
  65.         f = true
  66.         char["Left Arm"].Transparency = 1;char["Right Arm"].Transparency = 1
  67.         root = char.HumanoidRootPart
  68.        
  69.         local ting = game:GetService("ServerStorage").InvisHands:Clone() -- get the fake arms from the server storage
  70.         the = ting
  71.         ting.AnimSaves:Destroy()
  72.         ting.Parent = char
  73.        
  74.         for i,v in next, ting:GetChildren() do -- get the hands then recolor them
  75.             if v:IsA("Part") then
  76.                 if v.Name == "L1" or v.Name == "L2" then
  77.                     v.Color = char["Right Arm"].Color
  78.                 elseif v.Name == "R1" or v.Name == "R2" then
  79.                     v.Color = char["Left Arm"].Color
  80.                 end
  81.             end
  82.         end
  83.        
  84.         local weld = Instance.new("Motor6D",ting.Main) -- lock the barrage hands to the players root part
  85.         weld.Part0 = weld.Parent
  86.         weld.Part1 = char.HumanoidRootPart
  87.         char.HumanoidRootPart.Anchored = false -- unanchor the player
  88.  
  89.         local anim = script.Animation
  90.         ting.AnimationController.Animator:LoadAnimation(anim):Play() -- finally, play the barrage animation
  91.     end
  92. end)
  93.  
  94. tool.Deactivated:Connect(function() -- gets triggered when you deactivate the tool
  95.     if the ~= nil and f then -- check if you are attacking
  96.         f = false -- debounce
  97.         local char = tool.Parent -- your character
  98.         for i,v in next, the:GetChildren() do -- get the stuff in your character
  99.             if v:IsA("Part") then -- check if its a part
  100.                 local c = {};c.Transparency = 1 -- tween and stuff
  101.                 tween:Create(v,TweenInfo.new(0.5),c):Play() -- play the tween
  102.                 if v:FindFirstChildOfClass("Trail") then -- get the trail from the fake arms
  103.                     v.Trail.Enabled = false -- disable the trail
  104.                 end
  105.             end
  106.         end
  107.        
  108.         char["Left Arm"].Transparency = 0;char["Right Arm"].Transparency = 0 -- reshow the arms
  109.         local anim_start = script.Start -- again, the start animation
  110.         char.Humanoid.Animator:LoadAnimation(anim_start):Play();task.wait(0.5) -- play the animation
  111.  
  112.         for i,v in next, char:GetChildren() do
  113.             if v.Name == the.Name then
  114.                 v:Destroy();the:Destroy() -- destroy the barrage arms
  115.             end
  116.         end
  117.     end
  118. end)
  119.  
  120. spawn(function()
  121.     while task.wait() do
  122.         if f then
  123.             createSound(root,"rbxassetid://711753382",1,false,"punch fx");task.wait(0.1) -- the sound that plays while you are punching + debounce
  124.         end
  125.     end
  126. end)
  127.  
  128. -- made by eric/Er_1x/ERIC#2073 have fun
Add Comment
Please, Sign In to add comment