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
 

Why isn't this working?

Previous Thread :: Next Thread 
Antcient555678 is not online. Antcient555678
Joined: 07 Nov 2011
Total Posts: 679
19 Dec 2016 01:08 PM
tool.Handle.Touched:connect(function(hit)
if hit.Name == "Head" or "Torso" or "Right Arm" or "Left Arm" or "Right Leg" or "Left Leg" then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end)

14:07:47.724 - Script 'Players.Player1.Backpack.Knife.Script', Line 24
14:07:47.724 - Stack End
14:07:47.744 - Players.Player1.Backpack.Knife.Script:24: attempt to index field 'Parent' (a nil value)
14:07:47.745 - Stack Begin
14:07:47.746 - Script 'Players.Player1.Backpack.Knife.Script', Line 24
14:07:47.746 - Stack End

Parent isn't a nil value.


Report Abuse
C_Sharper is online. C_Sharper
Joined: 03 Oct 2011
Total Posts: 6405
19 Dec 2016 01:56 PM
What's happening here is you have an invalid if statement.


Unfortunately, Lua doesn't allow you to use syntax such as this.

You have to rewrite all of it by doing,

if hit.Name == "Head" or hit.Name == "Left Leg" --so on



What happens is, since the hit's name isn't Head, it goes on to your next check, which is "or "Left Leg""

And in this case, this is a non-nil string, so it passes through the if statement, however, the parent is nil. So that's why this is not working. Hope it helps!
Report Abuse
dexterofficial is not online. dexterofficial
Joined: 21 Sep 2015
Total Posts: 229
19 Dec 2016 01:59 PM
tool.Handle.Touched:connect(function(hit)
if hit.Name == "Head" or hit.Name == "Torso" or hit.Name == "Right Arm" or hit.Name == "Right Leg" or hit.Name == "Left Arm" or hit.Name == "Left Leg" then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end)
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