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: Why does this only work once?

Previous Thread :: Next Thread 
Rit957 is not online. Rit957
Joined: 19 Apr 2011
Total Posts: 3459
26 Jan 2013 11:49 AM
I am trying to make the simplest kill script ever but this one only works once

function onTouched(h)
h.Parent.Humanoid.Health=0

end

connection = script.Parent.Touched:connect(onTouched)
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
26 Jan 2013 11:54 AM
    script.Parent.Touched(function(hit)
      if hit.Parent:findFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = 0
      end
    end)
Report Abuse
As8D is online. As8D
Joined: 24 Dec 2009
Total Posts: 2907
26 Jan 2013 12:00 PM
Cody, remember missiles. hit.Parent can be nil! (Or... I think instant using the parent's method will work. Maybe it's just me, but if this is true, then I guess that there's a little delay when removing/destroying objects. Or that may just be in the script's code. Nvm.)


But yesh, Cody solved daz problemos.

- As. Why did I even visit http://roblox.com/user.aspx?id=1 in the first place? Dunno.
Report Abuse
TacoBowls is not online. TacoBowls
Joined: 02 Mar 2009
Total Posts: 112
26 Jan 2013 12:00 PM
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
h.Health = 0
end
end
script.Parent.Touched:connect(onTouched)

I'm guessing its a brick, when touched, kills the person. If so, this would be the correct way.
You forgot to define 'h' by the way.
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
26 Jan 2013 12:03 PM
"You forgot to define 'h' by the way."

>function onTouched(h)
Report Abuse
TacoBowls is not online. TacoBowls
Joined: 02 Mar 2009
Total Posts: 112
26 Jan 2013 12:11 PM
Wasn't paying attention because I changed it to (part) .
My bad.. But thanks for the notice.
Report Abuse
boomin3 is not online. boomin3
Joined: 06 Mar 2010
Total Posts: 87
26 Jan 2013 12:13 PM
1001
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