HowToRoblox

CreateFireball

Jul 29th, 2021 (edited)
1,909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. local re = game.ReplicatedStorage:WaitForChild("OnFireballThrown")
  2.  
  3.  
  4. local plrsOnCooldown = {}
  5.  
  6.  
  7. local ts = game:GetService("TweenService")
  8.  
  9.  
  10. re.OnServerEvent:Connect(function(plr, mouseCF)
  11.    
  12.    
  13.     if plrsOnCooldown[plr] then return end
  14.    
  15.     plrsOnCooldown[plr] = true
  16.    
  17.    
  18.     local hrp = plr.Character:WaitForChild("HumanoidRootPart")
  19.    
  20.    
  21.     local cf = CFrame.new(hrp.Position, mouseCF.Position)
  22.    
  23.     local newPos = cf.LookVector * 10000
  24.    
  25.    
  26.     local fireball = script:WaitForChild("Fireball"):Clone()
  27.    
  28.     fireball.CFrame = cf
  29.    
  30.    
  31.     local tweenTime = (hrp.Position - newPos).Magnitude / 100
  32.    
  33.     local ti = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  34.    
  35.    
  36.     local tween = ts:Create(fireball, ti, {Position = newPos})
  37.     tween:Play()
  38.    
  39.     tween.Completed:Connect(function()
  40.         fireball:Destroy()
  41.     end)
  42.    
  43.    
  44.     fireball.Touched:Connect(function(hit)
  45.        
  46.        
  47.         if hit.Parent ~= plr.Character then
  48.            
  49.            
  50.             if hit.Parent:FindFirstChild("Humanoid") then
  51.                
  52.                 hit.Parent.Humanoid:TakeDamage(30)
  53.                
  54.                
  55.                 local fires = {}
  56.                
  57.                 for i, child in pairs(hit.Parent:GetChildren()) do
  58.                    
  59.                     if child:IsA("BasePart") then
  60.                        
  61.                         local fire = Instance.new("Fire", child)
  62.                        
  63.                         table.insert(fires, fire)
  64.                     end
  65.                 end
  66.                
  67.                
  68.                 spawn(function()
  69.                    
  70.                     for i = 1, math.random(5, 10) do
  71.                        
  72.                         hit.Parent.Humanoid:TakeDamage(5)
  73.                        
  74.                         wait(1)
  75.                     end
  76.                    
  77.                    
  78.                     for i, fire in pairs(fires) do
  79.                         fire:Destroy()
  80.                     end
  81.                 end)
  82.             end
  83.            
  84.            
  85.             fireball:Destroy()
  86.         end
  87.     end)
  88.    
  89.    
  90.     fireball.Parent = workspace
  91.    
  92.    
  93.     wait(1)
  94.    
  95.     plrsOnCooldown[plr] = nil
  96. end)
Add Comment
Please, Sign In to add comment