skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 28 Dec 2013 04:34 PM |
CurAmmo = script.Parent.CurAmmo.Value MagAmount = script.Parent.MagAmount.Value Hit1 = math.random(50,115) Hit2 = math.random(50,90) Hit3 = math.random(50,65) RawDmg = (Hit1 + Hit2 + Hit3)/3 HitDmg = math.ceil(RawDmg) TotalAmmo = CurAmmo * MagAmount
--Bullet bulletFired = false
--Range Range = 5
--Cooldown Cooldown = 1.5
function AMMO() if TotalAmmo > 0 then Bullet() CurAmmo = CurAmmo - 1 else return end end
function Bullet() bullet = Instance.new("Part",game:GetService("Workspace")) bullet.Shape = "Ball" bullet.Name = "PreBullet" Instance.new("BodyThrust",game:GetService("Workspace").PreBullet) bullet.Name = "Bullet" bullet.Size = Vector3.new(.5,.5,.5) bullet.Position = script.Parent.Muzzle.Position bullet.BodyThrust.force = Vector3.new(100,0,0) bullet.BodyThrust.Location = Vector3.new(mouse.Origin) bulletFired = true if bulletFired == true and wait(Range) then Struck() print("Bullet has been fired") else bullet:Destroy() end end
function Struck() bullet.Touched:connect(function(hit) if hit.Parent:findFirstChild("ForceField") ~= nil then bullet:Destroy() bulletFired = false elseif hit.Parent:FindFirstChild("Humanoid") then hit.Parent:findFirstChild("Humanoid"):TakeDamage(HitDmg) bullet:Destroy() bulletFired = false else return end end) end
function onEquip(mouse) if mouse == nil then print("Mouse not found") return end
while TotalAmmo ~= 0 and CurAmmo ~= 0 do wait(Cooldown) mouse.Button1Down:connect(AMMO) mouse.Button2Down:connect(Scope) end end
while true do script.Parent.Equipped:connect(onEquip) end
I can run the game by pressing the play button just fine, but when I go to solo mode, it just completely crashes on me.
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
| 28 Dec 2013 04:35 PM |
while true do wait() script.Parent.Equipped:connect(onEquip) end
You need to add a wait in loops. |
|
|
| Report Abuse |
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 28 Dec 2013 04:35 PM |
while true do script.Parent.Equipped:connect(onEquip) end
? |
|
|
| Report Abuse |
|
|
| 28 Dec 2013 04:37 PM |
script.Parent.Equipped:connect(onEquip)
Actually, just remove the while true do. You already have the Equipped event so you don't need any loops. |
|
|
| Report Abuse |
|