✓ Accepted answer
##Problem
There are several things wrong with this script.
- You're referencing variables before they exist.
- You're trying to find a character and humanoid out of nowhere.
- And you're just trying to change the value of a variable when you're intending to change the health.
Your question does not have a summary of what is wrong with the script, nor did you even attempt to find the error. If you do not understand the RBX.Lua scripting language, then check out some some of the sources I have in this answer. They will help expand your understanding of the RBX.Lua scripting language.
##Solution
You're going to want to make a line to connect the touched event to a part. This can be done through an anonymous function, or you can create a separate function. With the Touched the event will return the object that hit what you're calling the "acid tank". With the object we want to find its humanoid through the player as humanoid is not inside the part that hit the acid, but rather inside the model which holds the part that hit the acid. So, I will post the final script. Try to follow along and if you do not understand a line, post a comment below this answer.
##Final Script
function BrickWasHit(Part)
if Part.Parent:FindFirstChild('Humanoid') then
Parent.Parent.Humanoid.Health = 0
end
end
script.Parent.Touched:connect(BrickWasHit)
######If this answer helped, hit the upvote button. If it answered your question do not forget to hit accept answer. If you have any questions feel free to post them in the comments below and I will try to answer them!
2 comments
http://www.lua.org/manual/5.1/
e.e i dont wanna buy stuff