FAMOUSMnM
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 21946 |
|
|
| 09 Dec 2012 12:16 AM |
but i want to start again, gives me another thing to do on roblox but, since i havn't in a while, i've lost most of my memory of it.
so, i am going to start off doing basic things, like messages and kill scripts
so would this work
function onTouched local humanoid = part.Parent:FindFirstChild("Humanoid") if humanoid =nil) then humanoid.Health = 0 end end
script.Parent.Touched:connect
sorry if it's really easy, but again, i have forgot how to script, so. please help |
|
|
| Report Abuse |
|
|
Dex1337
|
  |
| Joined: 01 Aug 2012 |
| Total Posts: 185 |
|
|
| 09 Dec 2012 12:35 AM |
function onTouch() local script = script.Parent:findFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
|
| 09 Dec 2012 12:38 AM |
No, that would not work. You are missing a parenthesis (which is not really needed), and you missed another = sign, when using the if statement. You also called your function wrong, it should be [Object].[Event]:connect([Function Name]). You also didn't include an open & closed parenthesis after your function. Nor an argument.
~ṡсɾïρτïṉģ hεlρεɾṡ ۩ lυαlεαɾṉεɾṡ ④ øƒвќṃṿј~ ღ ▂▃▅▆█ρεώḋïερïε☄сυτïερïε█▆▅▃▂ღ www.youtube.com/watch?v=N2GVu0A-vC4&feature=youtu.be
|
|
|
| Report Abuse |
|
|
|
| 09 Dec 2012 12:39 AM |
This is a more efficient way of doing it using an anonymous function:
script.Parent:Touched:connect(function (part) local humanoid = part.Parent:findFirstChild("Humanoid") if humanoid then humanoid.Health = 0 end end
But on your part, it would look like this:
function Touch(part) local humanoid = part.Parent:findFirstChild("Humanoid") if humanoid then humanoid.Health = 0 end end
script.Parent:Touched:connect(Touch)
You do however have the general idea of it.
~ṡсɾïρτïṉģ hεlρεɾṡ ۩ lυαlεαɾṉεɾṡ ④ øƒвќṃṿј~ ღ ▂▃▅▆█ρεώḋïερïε☄сυτïερïε█▆▅▃▂ღ www.youtube.com/watch?v=N2GVu0A-vC4&feature=youtu.be
~ṡсɾïρτïṉģ hεlρεɾṡ ۩ lυαlεαɾṉεɾṡ ④ øƒвќṃṿј~ ღ ▂▃▅▆█ρεώḋïερïε☄сυτïερïε█▆▅▃▂ღ www.youtube.com/watch?v=N2GVu0A-vC4&feature=youtu.be |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 09 Dec 2012 12:40 AM |
function onTouched(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 end end
script.Parent.Touched:connect(onTouched)
There |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 09 Dec 2012 12:41 AM |
"This is a more efficient way of doing it using an anonymous function:"
Not really. Using an anonymous function doesn't make it really efficient, it's just a shorter way of writing it. It's not efficient or at least, by not a lot. You shouldn't focus on this. Premature Optimization is the root of all evil.
|
|
|
| Report Abuse |
|
|
FAMOUSMnM
|
  |
| Joined: 15 Oct 2010 |
| Total Posts: 21946 |
|
| |
|
| |
|
| |
|