Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the error with this script?

Asked by
F_lipe 135
9 years ago

I'm trying to make this script kill a person when they touch it if the brick is not transparent.

This is what I have so far.

function onTouched(part)
              local human = script.Parent.Parent:findFirstChild("Humanoid")
              if script.Parent.Transparency == 0 then
              human:TakeDamage(100)
              end
end
script.Parent.Touched:connect(onTouched)
0
Please fix this so that it is in the code block format. Necrorave 560 — 9y

1 answer

Log in to vote
0
Answered by
Necrorave 560 Moderation Voter
9 years ago
function onTouched(part) --"part" is the piece of the human that will be touching the Parent of the script
if part.Parent:FindFirstChild("Humanoid") ~= nil then
    human = part.Parent:FindFirstChild("Humanoid") --Setting "Humanoid" to be set to "human"
    if script.Parent.Transparency == 0 then 
        human.Health = 0 --This will make the players health go to 0.  (Default death)
    end 
end
end 

script.Parent.Touched:connect(onTouched)

This should work, you had a lot of errors present.

First, when you are looking at function onTouched(part) keep in mind that part is the object we are going to be manipulating. That part will be the object touching the script's Parent.

I added a conditional statement that will check to see if the Parent of part has a "Humanoid" object in it. If it does, then it will check to see if the Parent of the script is transparent. If it is not transparent, it will kill the player.

If this does not help, let me know!

0
Sorry I messed the code block up. F_lipe 135 — 9y
0
No big deal. Necrorave 560 — 9y
0
I was trying to learn the :TakeDamage in the script but this did work thanks for the help. F_lipe 135 — 9y
0
Ah, my apologies. I have never used the "TakeDamage()" method. Maybe later I can look into it myself. No problem! Necrorave 560 — 9y
Ad

Answer this question