KrYn0MoRe

minecraft fireworks

Jan 20th, 2022 (edited)
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.96 KB | None | 0 0
  1. local plr = owner
  2. local char = plr.Character
  3. local root = char.HumanoidRootPart
  4.  
  5. local sprite = 137511594
  6.  
  7. local tool = Instance.new("Tool")
  8. tool.Name = 'Firework Rocket'
  9. tool.ToolTip = 'Go out with a bang!'
  10. tool.TextureId = 'rbxassetid://' .. sprite
  11. tool.Parent = plr.Backpack
  12.  
  13. local library = {
  14.     twinkle_far = 8597162279,
  15.     twinke = 8597161656,
  16.     large_blast_far = 8597161008,
  17.     large_blast = 8597160297,
  18.     launch = 8597159557,
  19. }
  20.  
  21. function play_sound(par,id,vol,speed,min,max)
  22.     local s = Instance.new("Sound")
  23.     s.SoundId = 'rbxassetid://' .. id
  24.     s.Volume = vol or 0.5
  25.     s.PlaybackSpeed = speed or 1
  26.     s.RollOffMaxDistance = max
  27.     s.RollOffMinDistance = min
  28.     s.Parent = par or root
  29.     s:Play()
  30.     s.Ended:Connect(function()
  31.         task.wait()
  32.         s:Destroy()
  33.     end)
  34.     return s
  35. end
  36.  
  37. pcall(function()
  38.     game:GetService("PhysicsService"):CreateCollisionGroup('fireworks')
  39.     game:GetService("PhysicsService"):CreateCollisionGroup('chars')
  40.     game:GetService("PhysicsService"):CollisionGroupSetCollidable('fireworks','chars',false)
  41.     game:GetService("PhysicsService"):CollisionGroupSetCollidable('fireworks','fireworks',false)
  42. end)
  43.  
  44. for i,v in ipairs(char:GetDescendants()) do
  45.     if v:IsA("BasePart") then
  46.         game:GetService("PhysicsService"):SetPartCollisionGroup(v,'chars')
  47.     end
  48. end
  49.  
  50. function filter_char(c)
  51.     if c ~= char then else return end
  52.     for i,v in ipairs(c:GetDescendants()) do
  53.         if v:IsA("BasePart") then
  54.             game:GetService("PhysicsService"):SetPartCollisionGroup(v,'chars')
  55.         end
  56.     end
  57. end
  58.  
  59. for i,v in ipairs(workspace:GetChildren()) do
  60.     if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") then
  61.         filter_char(v)
  62.     end
  63. end
  64. workspace.ChildAdded:Connect(function(v)
  65.     if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") then
  66.         filter_char(v)
  67.     end
  68. end)
  69.  
  70. function fire(pos)
  71.     local explosion = Instance.new("ParticleEmitter")
  72.     explosion.LightEmission = 1
  73.     explosion.LightInfluence = 0
  74.     explosion.Orientation = Enum.ParticleOrientation.FacingCamera
  75.     explosion.Texture = "rbxassetid://6995657416"
  76.     explosion.Transparency = NumberSequence.new(0,1)
  77.     explosion.Acceleration = Vector3.new(0,-5,0)
  78.     explosion.Drag = 0
  79.     explosion.EmissionDirection = Enum.NormalId.Top
  80.     explosion.Enabled = false
  81.     explosion.Lifetime = NumberRange.new(3, 3.1)
  82.     explosion.Rotation = NumberRange.new(45, 45)
  83.     explosion.RotSpeed = NumberRange.new(-500, 500)
  84.     explosion.Speed = NumberRange.new(70, 80)
  85.     explosion.Shape = Enum.ParticleEmitterShape.Sphere
  86.     explosion.ShapeStyle = Enum.ParticleEmitterShapeStyle.Surface
  87.     explosion.ShapeInOut = Enum.ParticleEmitterShapeInOut.Outward
  88.     explosion.ShapePartial = 1
  89.     explosion.Drag = 5
  90.    
  91.     local phy_part = Instance.new("Part")
  92.     phy_part.Transparency = 1
  93.     phy_part.Massless = true
  94.     phy_part.CanCollide = true
  95.     phy_part.Anchored = false
  96.     phy_part.Size = Vector3.new(1,1,1)
  97.     phy_part.CFrame = CFrame.new(pos)*CFrame.new(0,0.5,0)
  98.     game:GetService("PhysicsService"):SetPartCollisionGroup(phy_part,'fireworks')
  99.    
  100.     local att = Instance.new("Attachment")
  101.     att.Parent = phy_part
  102.    
  103.     local img = Instance.new("ParticleEmitter")
  104.     img.LightEmission = 0
  105.     img.LightInfluence = 0
  106.     img.Orientation = Enum.ParticleOrientation.FacingCameraWorldUp
  107.     img.Texture = "rbxassetid://" .. sprite
  108.     img.Transparency = NumberSequence.new(0)
  109.     img.Enabled = false
  110.     img.LockedToPart = true
  111.     img.Lifetime = NumberRange.new(1/0)
  112.     img.Speed = NumberRange.new(0)
  113.     img.SpreadAngle = Vector2.new(0,0)
  114.     img.Parent = att
  115.    
  116.     local force = Instance.new("BodyForce")
  117.     force.Parent = phy_part
  118.    
  119.     phy_part.Parent = script
  120.     img:Emit()
  121.    
  122.     local reduce_dist = 16*4
  123.    
  124.     play_sound(phy_part,library.launch,0.5,1,reduce_dist,reduce_dist*2)
  125.    
  126.     coroutine.wrap(function()
  127.         local st = os.clock()
  128.         local dur = 2 + math.random()*0.5
  129.         local y = phy_part:GetMass()
  130.         local x = 0.001
  131.         local z = 0.001
  132.         if math.random(1,2) == 1 then
  133.             x = -x
  134.         end
  135.         if math.random(1,2) == 1 then
  136.             z = -z
  137.         end
  138.        
  139.         repeat
  140.             local y = (y + 0.05*(os.clock()-st)*4) * workspace.Gravity
  141.             local x = (x*(os.clock()-st)*1.15*4) * workspace.Gravity
  142.             local z = (z*(os.clock()-st)*1.15*4) * workspace.Gravity
  143.             force.Force = Vector3.new(x,y,z)
  144.             task.wait()
  145.         until os.clock()-st >= dur
  146.        
  147.         phy_part.Anchored = true
  148.         local s = 8
  149.         --phy_part.Size = Vector3.new(s,s,s)
  150.         att:Destroy()
  151.         explosion.Parent = phy_part
  152.         explosion:Emit(300)
  153.        
  154.         play_sound(phy_part,library.large_blast_far,2,1,reduce_dist,reduce_dist*3)
  155.         task.wait(0.1)
  156.         play_sound(phy_part,library.twinkle_far,2,1,reduce_dist,reduce_dist*3)
  157.     end)()
  158. end
  159.  
  160. local last = 0
  161. local fire_id = 0
  162. local mouse_pos = Vector3.new()
  163. local firing = false
  164.  
  165. script.Parent = char
  166. local remote = Instance.new("RemoteEvent")
  167. remote.Parent = script
  168.  
  169. function equipped()
  170.     return tool:IsDescendantOf(char)
  171. end
  172.  
  173. remote.OnServerEvent:Connect(function(lplr,id,data)
  174.     if lplr == plr and equipped() then
  175.         if id == 1 then
  176.             if data and not firing then
  177.                 firing = true
  178.                 fire_id += 1
  179.                 local cid = fire_id
  180.                 local count = 0
  181.                
  182.                 while fire_id == cid do
  183.                     local cooldown = (5-count)/10
  184.                    
  185.                     if os.clock()-last >= cooldown then
  186.                         count += 1
  187.                         count = math.clamp(count,0,4)
  188.                         last = os.clock()
  189.                        
  190.                         fire(mouse_pos)
  191.                     end
  192.                    
  193.                     task.wait()
  194.                 end
  195.             else
  196.                 firing = false
  197.                 fire_id += 1
  198.             end
  199.         elseif id == 2 then
  200.             mouse_pos = data
  201.         end
  202.     end
  203. end)
  204.  
  205. NLS([[
  206. local plr = owner
  207. local mouse = plr:GetMouse()
  208. local remote = script.Parent
  209. mouse.TargetFilter = remote.Parent
  210.  
  211. game:GetService("UserInputService").InputBegan:Connect(function(input,gamepress)
  212.     if not gamepress then else return end
  213.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  214.         remote:FireServer(1,true)
  215.     end
  216. end)
  217. game:GetService("UserInputService").InputEnded:Connect(function(input,gamepress)
  218.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  219.         remote:FireServer(1,false)
  220.     end
  221. end)
  222.  
  223. while true do
  224.     remote:FireServer(2,mouse.Hit.Position)
  225.     task.wait(0.1)
  226. end
  227. ]],remote)
Add Comment
Please, Sign In to add comment