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: Need help with a very basic script

Previous Thread :: Next Thread 
LemmingHerder is not online. LemmingHerder
Joined: 05 Sep 2010
Total Posts: 6
06 Sep 2010 06:29 PM
I am new to scripting this is my second script so don't laugh

function OnTouched(Water)
local human = part.Parent:FindFirstChild("Humanoid")
if human ~= nil then
human.Health = 0
end
end


script.Parent.Touched:connect(OnTouched)

I want it to kill you when you touch the brick named Water
Report Abuse
unknown89089 is not online. unknown89089
Joined: 21 Aug 2008
Total Posts: 2961
06 Sep 2010 06:30 PM
function OnTouched(part)
local human = part.Parent:FindFirstChild("Humanoid")
if human ~= nil then
human.Health = 0
end
end

script.Parent.Touched:connect(OnTouched)


The function OnTouched(Water) was incorrect, the (Water) part basically names the touched brick.
Report Abuse
LemmingHerder is not online. LemmingHerder
Joined: 05 Sep 2010
Total Posts: 6
06 Sep 2010 06:32 PM
oh ok thanks
Report Abuse
LemmingHerder is not online. LemmingHerder
Joined: 05 Sep 2010
Total Posts: 6
06 Sep 2010 06:36 PM
I tried what you said it still doesn't work
I'm not sure if this changes anythink but the brik is walkthroughable
Report Abuse
unknown89089 is not online. unknown89089
Joined: 21 Aug 2008
Total Posts: 2961
06 Sep 2010 06:45 PM
It shouldn't... here's my script, not sure if there are any errors.

function OnTouched(hit)
if hit.Parent:findFirstChild("Humanoid") ~= nil then
hit.Parent:findFirstChild("Humanoid").Health = 0
end
end

script.Parent.Touched:connect(OnTouched)
Report Abuse
unknown89089 is not online. unknown89089
Joined: 21 Aug 2008
Total Posts: 2961
06 Sep 2010 06:48 PM
Oh right, found the problem, in findFirstChild:("Humanoid") you weren't supposed to capitalize find, LUA's really picky about capitalization.
Report Abuse
ninga95 is not online. ninga95
Joined: 16 Jul 2008
Total Posts: 5026
06 Sep 2010 06:49 PM
@Above heres a little more efficent i made a little similar


script.Parent.Touched:connect(function(Water)
if Water.Parent:FindFirstChild("Humanoid") ~= nil then
Water.Parent:FindFirstChild("Humanoid").Health = 0
end
end)
Report Abuse
LemmingHerder is not online. LemmingHerder
Joined: 05 Sep 2010
Total Posts: 6
06 Sep 2010 06:54 PM
Thanks to everyone that helped me with my second script
it is working now
Report Abuse
OBF is not online. OBF
Joined: 29 Sep 2009
Total Posts: 10709
06 Sep 2010 06:56 PM
NU! Not mch is more efficient than this:

script.Parent.Touched:connect(function(H)
pcall(function() H.Parent.Humanoid:TakeDamage(100) end)
end)
Report Abuse
ninga95 is not online. ninga95
Joined: 16 Jul 2008
Total Posts: 5026
06 Sep 2010 06:59 PM
Lol OBF of course that's more efficent.
Report Abuse
naknak is not online. naknak
Joined: 30 Jun 2008
Total Posts: 350
06 Sep 2010 07:35 PM
He wins...
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
06 Sep 2010 07:38 PM
@ninga

Actually, both :findFirstChild and :FindFirstChild work. Same with :getChildren and :GetChildren. I actually prefer capitalizing the first word as well.
Report Abuse
ninga95 is not online. ninga95
Joined: 16 Jul 2008
Total Posts: 5026
06 Sep 2010 07:42 PM
I never said that, and i prefer FindFirstChild more then findFirstChild
Report Abuse
unknown89089 is not online. unknown89089
Joined: 21 Aug 2008
Total Posts: 2961
06 Sep 2010 07:48 PM
Darn, I never knew that >.>
Report Abuse
naknak is not online. naknak
Joined: 30 Jun 2008
Total Posts: 350
06 Sep 2010 07:55 PM
The last time I tried to capitalize "find" it errored
Report Abuse
ninga95 is not online. ninga95
Joined: 16 Jul 2008
Total Posts: 5026
07 Sep 2010 12:25 AM
Lol FindFirstChild i think works better, but they both work the same i guess sooo yea.
Report Abuse
shipmaster4000 is not online. shipmaster4000
Joined: 29 Apr 2010
Total Posts: 2050
07 Sep 2010 12:27 AM
wait for function() you need something in the ()`s?
Report Abuse
ninga95 is not online. ninga95
Joined: 16 Jul 2008
Total Posts: 5026
07 Sep 2010 12:28 AM
I only bumped this to get to 1.5 k posts :)
Report Abuse
Xuriel is not online. Xuriel
Joined: 14 Jun 2010
Total Posts: 1615
07 Sep 2010 12:29 AM
I never use GetChildren()

I use children()

Same with GetService(), I use service()

Works with all functions that begin with get (Built in functions).
Report Abuse
ninga95 is not online. ninga95
Joined: 16 Jul 2008
Total Posts: 5026
07 Sep 2010 12:30 AM
I might do that :D
Report Abuse
nominate10 is not online. nominate10
Joined: 20 May 2008
Total Posts: 2545
07 Sep 2010 12:45 AM
@ninga
Sorry...I meant to direct my message @uknown :P

I prefer just writing GetChildren and GetService.
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