Advertisement
President_2000

Lightning Script

Dec 1st, 2020 (edited)
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.10 KB | None | 0 0
  1. --// Script By RoastedPresident2000
  2. game:GetService('ReplicatedStorage').ElectricZap.OnServerEvent:Connect(function(plr,MOUSE)
  3. local char = plr.Character
  4. local rarm = char:WaitForChild("RightHand")
  5. local larm = char:WaitForChild("LeftHand")
  6. local hed = char:WaitForChild("Head")
  7. local torso = char:WaitForChild("UpperTorso")
  8. local root = char:WaitForChild("HumanoidRootPart")
  9. local hum = char:FindFirstChildOfClass("Humanoid")
  10. local debris = game:GetService("Debris")
  11. local run = game:GetService("RunService")
  12. local rs = run.Heartbeat
  13. local DebrisModel = Instance.new("Model",char)
  14. DebrisModel.Name ="Debris"
  15. --//Turn Character To Position
  16. root.CFrame = CFrame.new(root.Position,Vector3.new(MOUSE.x,root.Position.Y,MOUSE.z))
  17.  
  18. local function findAllNearestTorso(pos,dist)
  19. local list = workspace:children()
  20. local torso ={}
  21. local temp = nil
  22. local human = nil
  23. local temp2 = nil
  24.     for x = 1,#list do
  25.         temp2 = list[x]
  26.             if (temp2.className =="Model") and (temp2 ~= char) then
  27.                 temp = temp2:findFirstChild("UpperTorso")
  28.                 human = temp2:findFirstChildOfClass("Humanoid")
  29.                     if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  30.                         if (temp.Position - pos).magnitude < dist then
  31.                             table.insert(torso,temp)
  32.                             dist =(temp.Position - pos).magnitude
  33.                         end
  34.                     end
  35.                 end
  36.             end
  37.     return torso
  38. end
  39. function sound(id,position,vol,pitch,start,finish)
  40.     coroutine.resume(coroutine.create(function()
  41.         local part = Instance.new("Part",workspace)
  42.         part.Position = position
  43.         part.Size = Vector3.new(0,0,0)
  44.         part.CanCollide = false
  45.         part.Transparency = 1
  46.         local sound = Instance.new("Sound",part)
  47.         sound.SoundId = "rbxassetid://"..id
  48.         repeat rs:wait() until sound.IsLoaded
  49.             if vol ~= nil then
  50.                 sound.Volume = vol
  51.             end
  52.             if pitch ~= nil then
  53.                 sound.PlaybackSpeed = pitch
  54.             end
  55.             if start ~= nil then
  56.                 sound.TimePosition = start
  57.             end
  58.             if finish ~= nil then
  59.                 debris:AddItem(part,finish-start)
  60.             else
  61.                 debris:AddItem(part,sound.TimeLength)
  62.             end
  63.             sound:Play()  
  64.         return sound
  65.     end))
  66. end
  67. local function computeDirection(vec)
  68. local lenSquared = vec.magnitude * vec.magnitude
  69. local invSqrt = 1 / math.sqrt(lenSquared)
  70.     return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
  71. end
  72.  
  73. local function Effect(mesh,size,transparency,material,color,position,rotation,positionchange,sizechange,rotationchange,transparencychange,acceleration)
  74. local part = Instance.new("Part",DebrisModel)
  75. part.Anchored = true
  76. part.CanCollide = false
  77. part.Size = Vector3.new(1,1,1)
  78. part.Transparency = transparency
  79. part.Material = material
  80. part.Color = color
  81. part.CFrame = CFrame.new(position)*CFrame.Angles(math.rad(rotation.X),math.rad(rotation.Y),math.rad(rotation.Z))
  82. local partmesh = Instance.new("SpecialMesh",part)
  83.     if tonumber(mesh)== nil then partmesh.MeshType = mesh else partmesh.MeshId ="rbxassetid://"..mesh end
  84.         partmesh.Scale = size
  85.         local pvalue = Instance.new("Vector3Value",part)
  86.         pvalue.Name ="Position"
  87.         pvalue.Value = positionchange
  88.         local svalue = Instance.new("Vector3Value",part)
  89.         svalue.Name ="Size"
  90.         svalue.Value = sizechange
  91.         local rvalue = Instance.new("Vector3Value",part)
  92.         rvalue.Name ="Rotation"
  93.         rvalue.Value = rotationchange
  94.         local tvalue = Instance.new("NumberValue",part)
  95.         tvalue.Name ="Transparency"
  96.         tvalue.Value = transparencychange
  97.         local avalue = Instance.new("NumberValue",part)
  98.         avalue.Name ="Acceleration"
  99.         avalue.Value = acceleration
  100.         part.Name ="EFFECT"
  101.     return part
  102. end
  103. local function Lightning(Part0,Part1,Times,Offset,Color,Thickness,Trans)
  104. local magz =(Part0 - Part1).magnitude
  105. local curpos = Part0
  106. local trz ={-Offset,Offset}
  107.     for i=1,Times do
  108.         local li = Instance.new("Part", DebrisModel)
  109.         li.TopSurface =0
  110.         li.Material = Enum.Material.Neon
  111.         li.BottomSurface = 0
  112.         li.Anchored = true
  113.         li.Locked = true
  114.         li.Transparency = Trans or 0.4
  115.         li.Color = Color
  116.         li.Shape = Enum.PartType.Cylinder
  117.         li.formFactor ="Custom"
  118.         li.CanCollide = false
  119.         li.Size = Vector3.new(Thickness,Thickness,magz/Times)
  120.         --//This Adds the Particle To the Lightning
  121.         --local LightningParticle = script.LightningParticle:Clone()
  122.         --LightningParticle.Parent = li
  123.         local lim = Instance.new("BlockMesh",li)
  124.         local Offzet = Vector3.new(trz[math.random(1,2)],trz[math.random(1,2)],trz[math.random(1,2)])
  125.         local trolpos = CFrame.new(curpos,Part1)*CFrame.new(0,0,magz/Times).p+Offzet
  126.             if Times == i then
  127.                 local magz2 =(curpos - Part1).magnitude
  128.                 li.Size = Vector3.new(Thickness,Thickness,magz2)
  129.                 li.CFrame = CFrame.new(curpos,Part1)*CFrame.new(0,0,-magz2/2)
  130.             else
  131.                 li.CFrame = CFrame.new(curpos,trolpos)*CFrame.new(0,0,magz/Times/2)
  132.             end
  133.         curpos = li.CFrame*CFrame.new(0,0,magz/Times/2).p
  134.         li.Name ="LIGHTNING"
  135.     end
  136. end
  137. local Position = rarm.Position-rarm.CFrame.upVector
  138. local Position1 = larm.Position-rarm.CFrame.upVector
  139. local Target = MOUSE.p
  140. local direction = Target - Position
  141. local direction = computeDirection(direction)
  142. local ray = Ray.new(Position,(Target-Position).unit*1048)
  143. local part, endPoint = workspace:FindPartOnRay(ray, char)
  144. --//This Deals Damage
  145.     --for i,v in pairs(findAllNearestTorso(endPoint,30)) do
  146.     --  v.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(v.Parent:FindFirstChildOfClass("Humanoid").MaxHealth/math.random(10,12))
  147.     --end
  148. sound(1202656211,root.Position,10,math.random(90,110)/100)
  149. --//This creates the lightning
  150. for i=1,10 do rs:Wait()
  151.     Lightning(rarm.Position-rarm.CFrame.upVector,endPoint, math.random(5,10), 2, Color3.fromRGB(math.random(100,150),160,255),.5,.05)
  152. end
  153.  
  154.        
  155. if char then
  156.     local LightningGroup = DebrisModel:GetChildren()
  157.     repeat rs:Wait()
  158.         for i=1,#LightningGroup do
  159.             if LightningGroup[i]:FindFirstChildOfClass("BlockMesh").Scale.X > 0 then
  160.                 LightningGroup[i]:FindFirstChildOfClass("BlockMesh").Scale = LightningGroup[i]:FindFirstChildOfClass("BlockMesh").Scale - Vector3.new(0.1,0.1,0)
  161.             elseif LightningGroup[i]:FindFirstChildOfClass("BlockMesh").Scale.X <= 0 then
  162.                 LightningGroup[i]:Destroy()
  163.             end
  164.         end
  165.     until DebrisModel:FindFirstChild('LIGHTNING') == nil or DebrisModel == nil
  166.     DebrisModel:Destroy()
  167.     end
  168. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement