Advertisement
HowToRoblox

LightningStaffServer

Sep 4th, 2022
2,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.82 KB | None | 0 0
  1. local folder = game.ReplicatedStorage:WaitForChild("LightningStaffReplicatedStorage")
  2. local re = folder:WaitForChild("RemoteEvent")
  3.  
  4. local cooldowns = {}
  5.  
  6.  
  7. re.OnServerEvent:Connect(function(plr, tool, mouseHit)
  8.    
  9.     local char = plr.Character
  10.    
  11.     if not cooldowns[plr] and char and tool.Parent == char and char.Humanoid.Health > 0 then
  12.        
  13.         local hrp = char.HumanoidRootPart
  14.        
  15.         local distance = (mouseHit.Position - hrp.Position).Magnitude
  16.        
  17.         if distance <= 40 then
  18.        
  19.             cooldowns[plr] = true
  20.             re:FireClient(plr, "cooldownOn")
  21.            
  22.             local hitCF = CFrame.new(mouseHit.Position, Vector3.new(hrp.Position.X, mouseHit.Position.Y, hrp.Position.Z))
  23.             local cloudCF = hitCF + Vector3.new(0, 35, 0)
  24.            
  25.             local cloud = folder.Cloud:Clone()
  26.             cloud.CFrame = cloudCF
  27.             cloud.Parent = workspace
  28.             game:GetService("Debris"):AddItem(cloud, 20)
  29.            
  30.             task.wait(0.7)
  31.            
  32.             local glow = folder.CloudGlow:Clone()
  33.             glow.CFrame = cloudCF
  34.             glow.Parent = workspace
  35.            
  36.             local attachmentsList = {}
  37.             local attachmentsAmount = math.random(7, 11)
  38.            
  39.             local increment = (hitCF.Position - cloudCF.Position).Magnitude / attachmentsAmount
  40.            
  41.             local lastWidth = Random.new():NextNumber(0.5, 1.3)
  42.            
  43.             task.spawn(function()
  44.                 for i = 1, attachmentsAmount do
  45.                    
  46.                     local attachment = Instance.new("Attachment")
  47.                     game:GetService("Debris"):AddItem(attachment, 0.5)
  48.                     table.insert(attachmentsList, attachment)
  49.                    
  50.                     local basePos = Vector3.new(0, -(i-1) * increment, 0)
  51.                     local rx = Random.new():NextNumber(-4, 4)
  52.                     local ry = Random.new():NextNumber(-3, 3)
  53.                     local rz = Random.new():NextNumber(-4, 4)
  54.                     basePos += Vector3.new(rx, ry, rz)
  55.                    
  56.                     if i == 1 then
  57.                         basePos = Vector3.new(0, 0, 0)
  58.                    
  59.                     elseif i == attachmentsAmount then
  60.                         basePos =  hitCF.Position - cloudCF.Position
  61.  
  62.                         re:FireAllClients("cameraShake", hitCF.Position)
  63.                        
  64.                         local min = hitCF.Position - Vector3.new(folder.StrikeArea.Size.X/2, 0, folder.StrikeArea.Size.Z/2)
  65.                         local max = hitCF.Position + Vector3.new(folder.StrikeArea.Size.X/2, 10, folder.StrikeArea.Size.Z/2)
  66.                         local region = Region3.new(min, max)
  67.  
  68.                         local parts = workspace:FindPartsInRegion3(region, nil, 1000)
  69.  
  70.                         for i, part in pairs(parts) do
  71.                             if part.Name == "HumanoidRootPart" then
  72.                                 local distance = (hitCF.Position - Vector3.new(part.Position.X, hitCF.Position.Y, part.Position.Z)).Magnitude
  73.                                 if distance <= folder.StrikeArea.Size.X/2 then
  74.                                     part.Parent.Humanoid:TakeDamage(50)
  75.                                 end
  76.                             end
  77.                         end
  78.                     end
  79.                    
  80.                     attachment.Position = basePos
  81.                     attachment.Parent = cloud
  82.                    
  83.                     if i > 1 then
  84.                         local beam = Instance.new("Beam")
  85.                         game:GetService("Debris"):AddItem(beam, 0.5)
  86.                         beam.Parent = cloud
  87.                        
  88.                         beam.Attachment0 = attachmentsList[i-1]
  89.                         beam.Attachment1 = attachment
  90.                        
  91.                         beam.Color = ColorSequence.new{ColorSequenceKeypoint.new(0, Color3.fromRGB(135, 143, 255)), ColorSequenceKeypoint.new(1, Color3.fromRGB(135, 143, 255))}
  92.                         beam.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(1, 0)}
  93.                         beam.LightInfluence = 0
  94.                         beam.Brightness = 5
  95.                         beam.LightEmission = 5
  96.                         beam.FaceCamera = true
  97.                        
  98.                         beam.Width0 = lastWidth
  99.                        
  100.                         local randomWidth = math.clamp(lastWidth + Random.new():NextNumber(-0.4, 0.2), 0.1, 1)
  101.                         beam.Width1 = randomWidth
  102.                         lastWidth = randomWidth
  103.                     end
  104.                    
  105.                     task.wait(Random.new():NextNumber(0.03, 0.05))
  106.                 end
  107.                
  108.                 cloud.CloudParticles.Enabled = false
  109.             end)
  110.            
  111.             task.wait(0.2)
  112.             glow.Attachment.GlowParticles.Enabled = false
  113.             game:GetService("Debris"):AddItem(glow, 1)
  114.            
  115.             task.wait(5)
  116.             cooldowns[plr] = false
  117.             re:FireClient(plr, "cooldownOff")
  118.         end
  119.     end
  120. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement