logmanjr
|
  |
| Joined: 13 May 2008 |
| Total Posts: 10075 |
|
|
| 13 Aug 2012 03:49 PM |
I am VERY new to scripting and I'm currently trying to just make a lava brick that kills on touch.
function onTouched(hit) workspace.players.humanoid.random.health=0
This is what I tried how can I make that work? |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 03:55 PM |
Alright i'll show you two ways, first the complicated function.
script.Parent.Touched:connect(function(hit) player = hit.Parent:findFirstChild("Humanoid") if not player then return end player.Health = 0 end)
or the way your doing it
function onTouched(hit) player = hit.Parent:FindFirstChild("Humanoid") if not player then return end player.Health = 0 end end script.Parent.Touched:connect(onTouched)
Do you want me to explain it to you? |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 03:57 PM |
@Jayskull - You have an extra end in the second one.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 03:58 PM |
| I musta skipped over that, I saw my if and forget I returned it already:p |
|
|
| Report Abuse |
|
|
logmanjr
|
  |
| Joined: 13 May 2008 |
| Total Posts: 10075 |
|
|
| 13 Aug 2012 03:59 PM |
| Explaining would be great, thank you. Atleast I got the first line right :) |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 04:06 PM |
:D Not only that but you actually tried...more then most do these days. Anyway lets break this down, ignore the first script as its a bit complex.
function onTouched(hit) -- names the function, it can be whatever you want, the (hit) is what we use to identify whats happening, in this case whatever touches the brick
player = hit.Parent:FindFirstChild("Humanoid") -- If something hits this brick that doesn't have health, the script would break. To fix that, we check for a humanoid, and since the thing thats hitting it would most likely by the legs of a character, we know that hit.Parent is the player in the workspace
if not player then return end -- This actually checks if the player exists, or like I said if they have health. Its the same as saying if player ~= (does not equal) false then return end. Saying return end makes it stop the function so it doesn't break.
player.Health = 0 -- Kill them
end -- End the function
script.Parent.Touched:connect(onTouched) -- The event receiver! This is the most important part of a function. Not all use them, but any that are like checking for players entering the game, or a player touching a brick ect. use them. In this case, script.Parent is your brick, which is where the action will take place. Saying .Touched is how the function knows its looking for something to hit it, then you have to connect the function. So :connect(TheFuncTionname) in your case onTouched.
Do you want me to explain it to you? |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 04:11 PM |
| Ignore that last line, I copied the first script so it was still there |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 04:33 PM |
...How are anonymous functions complex? If anything, it's even simpler.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 04:47 PM |
| Sure if you know how to script they are easy. But someone just learning would have a lot of issues. Since he is just learning, it's a lot easier to not use them. |
|
|
| Report Abuse |
|
|
|
| 13 Aug 2012 07:15 PM |
How? Tell me, how is it any easier or different?
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|