Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the error with this script?

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)

1 comment

0

Please fix this so that it is in the code block format.

1 answer

✓ Accepted answer
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!

4 comments

0

Sorry I messed the code block up.

0

No big deal.

0

I was trying to learn the :TakeDamage in the script but this did work thanks for the help.

0

Ah, my apologies. I have never used the "TakeDamage()" method. Maybe later I can look into it myself. No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.