generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

My game keeps crashing, is this script the reason for it?

Previous Thread :: Next Thread 
skyarex is not online. 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
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
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 is not online. 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
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image