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 » Scripters
Home Search
 

Re: What could be added to stop this from breaking

Previous Thread :: Next Thread 
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 06:04 PM
Basicly what happens in a new gun script im trying out is if the bullet hits anything but a zombie, the gun jams and nothing works anymore


else
local Damage = math.random(BulletDamage - 5, BulletDamage + 5)
hit.Parent.Zombie:TakeDamage(Damage)



i know why it does it, i just dont know how to fix it
Report Abuse
anaIyze is not online. anaIyze
Joined: 29 May 2014
Total Posts: 2048
26 Nov 2014 06:05 PM
need full code
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
26 Nov 2014 06:06 PM
That should work, but you need an if statement to check if it HAS hit a zombie

if hit.Parent:FindFirstChild ("Zombie") then
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
26 Nov 2014 06:07 PM
A rock or a wall wouldn't have a humanoid, so that filters it out so that it doesn't try to use a method (the :TakeDamage ()) on something that isn't there
Report Abuse
Dicentium is not online. Dicentium
Joined: 28 Aug 2011
Total Posts: 18560
26 Nov 2014 06:09 PM
if hit.Parent:FindFirstChild("Zombie") ~= nil then
hit.Parent.Zombie:TakeDamage(Damage)
end
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
26 Nov 2014 06:10 PM
the ~= nil isn't necessary

wiki.roblox.com/index.php?title=Writing_Clean_Code
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 06:10 PM
@anaIyze
the full code is like 1200 lines

http://www.roblox.com/Problems-item?id=188747210

you can take the model of it though, its at line 717
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
26 Nov 2014 06:11 PM
nooo, you don't need the full code. He just didn't read the problem at the top (that's what I did at first)
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 06:13 PM
ah

anyway, i replaced the code and the output is still the same,

TakeDamage is not a valid member of Model
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
26 Nov 2014 06:15 PM
I thought Zombie was the name of the humanoid.

Can I see the hierarchy of your zombie down to the humanoid?

Workspace.Maxomega3.Humanoid is mine
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 06:17 PM
Workspace.Zombie.Zombie
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
26 Nov 2014 06:24 PM
Omitting the ~= nil is not writing clean code, and is confusing as hell to anyone who doesn't know that Lua will handle non-booleans (besides nil) as true in conditions.

Conditions are boolean expressions, and I'd actually advise keeping the not equal to nil, because that evaluates to a boolean and makes sense. Same deal with "while wait(1) do".
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
26 Nov 2014 06:25 PM
If you're using my if statement properly, then it shouldn't call TakeDamage on anything besides a zombie!

if hit.Parent:FindFirstChild ("Zombie") then
hit.Parent.Zombie:TakeDamage (Damage)
end
Report Abuse
anaIyze is not online. anaIyze
Joined: 29 May 2014
Total Posts: 2048
26 Nov 2014 06:47 PM
which script is erroring
in the gun or zombie
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 08:22 PM
@max either i put it in wrong or that didnt fix it

@Analyze, the gun, the zombie takes damage, but if you shoot anything other than the zombie (example being the baseplate) then the gun jams and stops shooting
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 08:37 PM
It might also be this line

if hit then
if hit.Parent then
if hit.Parent:findFirstChild("Zombie") then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor ~= Player.TeamColor or game.Players:GetPlayerFromCharacter(hit.Parent).Neutral == true then
local Damage = math.random(BulletDamage - 5, BulletDamage + 5)
hit.Parent.Zombie :TakeDamage(Damage)

because maybe the script is trying to find the player team of the zombie (the zombie in the script use to be humanoid) it breaks?
or somethign idk
Report Abuse
anaIyze is not online. anaIyze
Joined: 29 May 2014
Total Posts: 2048
26 Nov 2014 08:49 PM
it's erroring because the :takeDamage() is being called on only the humanoid and no part is being returned (to deny using :takeDamage(); on)
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 08:57 PM
alright, now what would i do to fix such a problem
im not exactly the most script intelegent person
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
26 Nov 2014 09:22 PM
Put the code that errors in a pcall until you find an actual solution. Pcall will keep the code running even if there is an error.

pcall(function()
--Put buggy code here
end)
Report Abuse
ash877 is not online. ash877
Joined: 18 Feb 2008
Total Posts: 5142
26 Nov 2014 09:32 PM
pcall(function()
hit.Parent.Zombie:TakeDamage(Damage)

end)
Report Abuse
ash877 is not online. ash877
Joined: 18 Feb 2008
Total Posts: 5142
26 Nov 2014 09:33 PM
temp. fix, but the crosshairs still have dat tho when it hits a part :P
Report Abuse
ash877 is not online. ash877
Joined: 18 Feb 2008
Total Posts: 5142
26 Nov 2014 09:35 PM
also at line 799

local Damage = math.random(BulletDamage - 5, BulletDamage + 5)
pcall(function()
hit.Parent.Parent.Zombie:TakeDamage(Damage)
end)
Report Abuse
ash877 is not online. ash877
Joined: 18 Feb 2008
Total Posts: 5142
26 Nov 2014 09:38 PM
replace line 806 w/ this

NewForce.force = game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * 5000
Report Abuse
nooooooo is not online. nooooooo
Joined: 15 Jun 2008
Total Posts: 21802
26 Nov 2014 10:23 PM
thanks for the help everyone
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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