I am make a gun and everything is perfectly fine but i need to make mags in this script and I don't know how. Here is the script:
Player = game.Players.LocalPlayer Gun = script.Parent Ammo = 20 MaxAmmo = 20 mouse = Player:GetMouse() BulletDamage = 10 enabled = true function Shoot() if Ammo >= 1 and enabled == true then enabled = false IsFiring = true Firing() end end function Firing() repeat wait(0.3) function Damage(Part) if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.Name ~= Player.Name then Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -BulletDamage Bullet:Destroy() end end Ammo = Ammo -1 print("You have "..Ammo.." ammo left!") enabled = false Bullet = Instance.new("Part", Workspace) Gun.GripPos = Vector3.new(0,0.3,0) game.Debris:AddItem(Bullet,2) Bullet.Shape = "Ball" Bullet.Size = Vector3.new(0.1,0.1,0.1) Bullet.TopSurface = "Smooth" Bullet.BottomSurface = "Smooth" Bullet.BrickColor = BrickColor.new("Really black") Bullet.CanCollide = false Bullet.CFrame = Gun.Handle.CFrame Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p) BM = Instance.new("SpecialMesh",Bullet) BM.MeshType = "Sphere" BM.Scale = Vector3.new(0.2,0.2,0.2) v = Instance.new("BodyVelocity", Bullet) v.velocity = Bullet.CFrame.lookVector *90 v.maxForce = Vector3.new(math.huge,math.huge,math.huge) Fire = Instance.new("Sound", Bullet) Fire.SoundId = "http://www.roblox.com/asset/?id=131419157" RP = math.random(10,20) RP = RP/10 Fire.Pitch = RP RV = math.random(70,90) RV = RV/10 Fire.Volume = RV Fire:Play() game.Debris:AddItem(Fire, 2) Bullet.Touched:connect(Damage) wait() Gun.GripPos = Vector3.new(0,0,0) enabled = true until IsFiring == false or Ammo == 0 end function StopShooting() IsFiring = false end function Reload(key) key = key:lower() if enabled == true and Ammo < 20 and key == "r" then enabled = false RS = Player.Character.Torso["Right Shoulder"] for i = 1,4 do RS.C0 = RS.C0 *CFrame.Angles(0,0,0.2) wait() end repeat wait(0.1) Ammo = Ammo +1 RS.C0 = RS.C0 *CFrame.Angles(0.2,0,0) Shell = Instance.new("Part",Workspace) Shell.TopSurface = "Smooth" Shell.BottomSurface = "Smooth" Shell.Reflectance = 0.01 Shell.BrickColor =BrickColor.new "Black" Shell.CanCollide = false Shell.Size = Vector3.new(1, 1, 1) ShellMesh = Instance.new("BlockMesh",Shell) ShellMesh.Scale = Vector3.new(0.2,0.3,0.45) game.Debris:AddItem(Shell,0.8) Shell.CFrame = Gun.Handle.CFrame *CFrame.new(0,-0.5,-0.3) wait(0.1) RS.C0 = RS.C0 *CFrame.Angles(-0.2,0,0) until Ammo == MaxAmmo for i = 1,4 do RS.C0 = RS.C0 *CFrame.Angles(0,0,-0.2) wait() end wait() enabled = true end end mouse.KeyDown:connect(Reload) Gun.Deactivated:connect(StopShooting) Gun.Activated:connect(Shoot)
Please help THANKS!