Advertisement
Guest User

[FIXED] Roblox Studio Gun Script

a guest
Mar 26th, 2020
14,599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. player = game.Players.LocalPlayer
  2. mouse = player:GetMouse()
  3. maxAmmo = 250
  4. ammo = maxAmmo
  5. rate = 0.002
  6. firing= false
  7. canFire= true
  8. reload = 2
  9. damage = 12
  10. script.Parent.Activated:Connect(function()
  11.     if ammo >= 1 and canFire == true then
  12.         firing = true
  13.         repeat local bullet= Instance.new("Part", workspace)
  14.             bullet.CanCollide = false
  15.             bullet.Shape = "Ball"
  16.             bullet.Material = "Neon"
  17.             bullet.BrickColor = BrickColor.new("Bright red")
  18.             bullet.Size = Vector3.new(0.4,0.4,0.4)
  19.             local Axis = CFrame.new(script.Parent.Handle.Position, mouse.Hit.p)
  20.             local spread = math.rad(2)
  21.             local Theta = math.random() * math.pi * 2
  22.             local Phi = math.random() * spread
  23.             local x = math.cos(Theta) * math.sin(Phi)
  24.             local y = math.sin(Theta) * math.sin(Phi)
  25.             local z = math.cos(Phi)
  26.             local Coordinate = Axis * CFrame.fromEulerAnglesXYZ(x,y,z)
  27.             bullet.CFrame = Coordinate
  28.             local vel = Instance.new("BodyVelocity")
  29.             vel.Velocity = bullet.CFrame.LookVector*250
  30.             game.Debris:AddItem(bullet, 15)
  31.             bullet.Touched:Connect(function(hit)
  32.                 if hit.Parent ~= player.Character and hit.Parent:FindFirstChild("Humanoid") then
  33.                     hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
  34.                     bullet:Destroy()
  35.                 end
  36.             end)   
  37.             wait(rate)
  38.         until ammo < 1 or firing == false
  39.     end
  40. end)
  41. script.Parent.Deactivated:Connect(function()
  42.     if firing == true then
  43.         firing = false
  44.     end
  45. end)
  46. mouse.KeyDown:Connect(function(k)
  47.     if string.lower(k) == "r" and ammo < maxAmmo and firing == false then
  48.         canFire = false
  49.         wait(reload)
  50.         ammo = maxAmmo
  51.         canFire = true
  52.     end
  53. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement