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
 

Re: Armour damage problem

Previous Thread :: Next Thread 
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
05 Mar 2012 01:17 PM
For some reason this script isn't picking up the humanoid it's looking for. Any thoughts?:

ball = script.Parent
damage = 5
Armour = nil
Humanoid2 = ""



function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if hit.Parent:FindFirstChild("Infected") == nil then
if humanoid ~= nil then
Humanoid2 = hit.Parent.Name
connection:disconnect()
if hit.Parent:FindFirstChild("Chest") ~= nil and hit.Parent:FindFirstChild("Chest").ArmourHP.Value > 0 then
Armour = hit.Parent:FindFirstChild("Chest")
Armour.ArmourHP.Value = Armour.ArmourHP.Value - damage
end
else
game.Workspace:FindFirstChild(Humanoid2).Humanoid:TakeDamage(damage)
end
end
end



connection = ball.Touched:connect(onTouched)

wait(3)
ball:remove()


Output:

19:17:33 - Workspace.Bullet.Paintball:19: attempt to index a nil value
19:17:33 - Script "Workspace.Bullet.Paintball", Line 19
19:17:33 - stack end
19:17:33 - Disconnected event because of exception
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
05 Mar 2012 01:46 PM
Which is line 19?

† KMXD †
Report Abuse
Lightmaster9 is not online. Lightmaster9
Joined: 14 May 2009
Total Posts: 8659
05 Mar 2012 01:48 PM
Change "Chest" to "Torso".
Report Abuse
Torcus is not online. Torcus
Joined: 22 Feb 2012
Total Posts: 885
05 Mar 2012 01:49 PM
...Your seriously using 'Chest'? If you want it to be chest, change torso to chest. Problem solved!
Report Abuse
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
05 Mar 2012 01:50 PM
"Chest" is the model of a morph that contains the ArmourHP IntValue.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
05 Mar 2012 01:50 PM
Line 19?

† KMXD †
Report Abuse
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
05 Mar 2012 01:53 PM
"game.Workspace:FindFirstChild(Humanoid2).Humanoid:TakeDamage(damage)"
Report Abuse
Torcus is not online. Torcus
Joined: 22 Feb 2012
Total Posts: 885
05 Mar 2012 01:58 PM
@Stroudie,

Welcome to my world. I'm taking a test just to get Scripter Tier-1 in Scripting Helpers Group.
Report Abuse
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
05 Mar 2012 02:00 PM
>_>
Report Abuse
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
05 Mar 2012 02:04 PM
Any ideas?
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
05 Mar 2012 02:07 PM
Try:

ball = script.Parent
damage = 5
Armour = nil
Humanoid2 = ""

function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
if not hit.Parent:FindFirstChild("Infected") then
Humanoid2 = hit.Parent.Name
connection:disconnect()
if hit.Parent:FindFirstChild("Chest") ~= nil and hit.Parent:FindFirstChild("Chest").ArmourHP.Value ​> 0 then
Armour = hit.Parent:FindFirstChild("Chest")
Armour.ArmourHP.Value = Armour.ArmourHP.Value - damage
end
else
game.Workspace:FindFirstChild(Humanoid2).Humanoid:TakeDamage(damage)
end
end
end
connection = ball.Touched:connect(onTouched)
wait(3)
ball:remove()

???

† KMXD †
Report Abuse
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
06 Mar 2012 11:06 AM
Made no difference.
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
06 Mar 2012 12:49 PM
Humanoid2 = ""

game.Workspace:FindFirstChild(Humanoid2)

So, it has no name..?

Also..


if hit.Parent:FindFirstChild("Chest") ~= nil and hit.Parent:FindFirstChild("Chest").ArmourHP.Value > 0 then
Armour = hit.Parent:FindFirstChild("Chest")
Armour.ArmourHP.Value = Armour.ArmourHP.Value - damage
end
else

I think that you meant to put that end after the else part, so that the else works with that if statement?
Report Abuse
stroudie is not online. stroudie
Joined: 28 Nov 2008
Total Posts: 2556
06 Mar 2012 03:52 PM
Nevermind now. I re-scripted it from scratch which fixed it.
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