Hergest
|
  |
| Joined: 17 May 2011 |
| Total Posts: 309 |
|
|
| 31 Dec 2012 08:24 PM |
So basically i started learning Lua and i love it. So i tried to create a reset brick. Here is my script:
function onTouched() game.Workspace.Hergest.Head:remove() end script.Parent.Touched(onTouched)
So.. What did exactly do wrong? |
|
|
| Report Abuse |
|
|
Z007
|
  |
| Joined: 14 Sep 2010 |
| Total Posts: 11729 |
|
|
| 31 Dec 2012 08:26 PM |
This should work. function onTouched() game.Workspace.Hergest.Head:Remove() end script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
ninja5566
|
  |
| Joined: 14 Jan 2009 |
| Total Posts: 5233 |
|
|
| 31 Dec 2012 08:27 PM |
script.Parent.Touched:connect(function(hit) player = game.Players:getPlayerFromCharacter(hit.Parent) if player ~= nil then a = hit.Parent:findFirstChild("Humanoid") if a ~= nil then a.Parent.Head:Destroy() end end end) |
|
|
| Report Abuse |
|
|
Hergest
|
  |
| Joined: 17 May 2011 |
| Total Posts: 309 |
|
|
| 31 Dec 2012 08:41 PM |
| ZOO, your script didn't work. :/ Ninja's script did but it's too confusing for me. I'm supposed to learn. :P |
|
|
| Report Abuse |
|
|
|
| 31 Dec 2012 08:58 PM |
I'll try to make it easier...
function onTouched(hit) --hit is the part that hit if hit.Parent:FindFirstChild("Humanoid") then --checks if a human hit the brick hit.Parent.Head:Destroy() --Removes the head end end
script.Parent.Touched:connect(onTouched)
That should work. I hope I simplified it for you.
|
|
|
| Report Abuse |
|
|
ninja5566
|
  |
| Joined: 14 Jan 2009 |
| Total Posts: 5233 |
|
|
| 31 Dec 2012 09:00 PM |
function touched(hit) --Hit, is the object touched. humanoid = hit.Parent:findFirstChild("Humanoid") --It must have a humanoid if humanoid ~= nil then --If humanoid is real then it will find the head and kill it humanoid.Parent.Head:Destroy() --Finding the head and destroying it. end end script.Parent.Touched:connect(touched)
The only reason my other one was advanced because I was making sure if it was hit it is a REAL player not a fake block with a humanoid in it, for example if a block with a humanoid hit it, it would break the script. |
|
|
| Report Abuse |
|
|
doneyes
|
  |
| Joined: 21 Mar 2008 |
| Total Posts: 3466 |
|
|
| 31 Dec 2012 09:24 PM |
| If you are testing it in studio, notice your name is Player1. |
|
|
| Report Abuse |
|
|
zack785
|
  |
| Joined: 06 Feb 2009 |
| Total Posts: 419 |
|
|
| 31 Dec 2012 09:37 PM |
script.Parent.Touched:connect(function(hit) --It's the function onTouch thing in different wording player = game.Players:getPlayerFromCharacter(hit.Parent) --The person that touched that; it checks if it's a person in Players too if player ~= nil then a = hit.Parent:findFirstChild("Humanoid") --Basically making sure whoever touched it has a humanoid if a ~= nil then --it means if there is a Humanoid a.Parent.Head:Destroy() --a(Humanoid).Parent(so the person) and the goes to there head and destroys it, I perfer a.Parent.Head:remove() end end end) |
|
|
| Report Abuse |
|
|
zack785
|
  |
| Joined: 06 Feb 2009 |
| Total Posts: 419 |
|
| |
|
zack785
|
  |
| Joined: 06 Feb 2009 |
| Total Posts: 419 |
|
|
| 31 Dec 2012 09:40 PM |
| Did my explanation help at all? |
|
|
| Report Abuse |
|
|