im trying to make an acid tank that when touched kills you heres my code:
local function EffectsOfAcid() local hp = char.Humanoid.Health local char = character hp = 0 end end end touched:connect(EffectsOfAcid) local touched = sp.Touched local sp = script.Parent
also say bye bc ima quit dis bc I KEEP FRIGGIN GETTING NEGATIVE REPUTATION
There are several things wrong with this script.
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.
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.
function BrickWasHit(Part) --We're establishing the function here. BrickWasHit is basically a variable that we will use in the connection line of the Touched event. if Part.Parent:FindFirstChild('Humanoid') then --If the script can find an object named humanoid in the part of the part that hit the acid, then the script should resume. Parent.Parent.Humanoid.Health = 0 --This will change the humanoid's health to zero. end --End the if then statement. end --We end the BrickWasHit function. script.Parent.Touched:connect(BrickWasHit) --Here we connect to the Touched event, and call the function BrickWasHit.
local function EffectsOfAcid() -- Why did you do a local function? local hp = char.Humanoid.Health -- Not sure, but as much as I know you can't define values as variables local char = character -- The char variable has to be defined to be used hp = 0 end -- Too many ends end end touched:connect(EffectsOfAcid) -- No event! local touched = sp.Touched local sp = script.Parent -- Same problem here!
That script really needs fixing and I'd propose you to do the ROBLOX wiki tutorials first. http://wiki.roblox.com/index.php/Studio This would be the fixed version with explanation:
local function EffectsOfAcid() local h = character.Humanoid h.Health = 0 end script.Parent.Touched:connect(EffectsOfAcid) -- Touched is the needed event
It mostly just has to do with your placement of "ends" and such. Here, if you have any questions, just comment:
script.Parent.Touched:connect(function(part) if part.Parent and part.Parent:FindFirstChild("Humanoid") ~= nil then part.Parent:FindFirstChild("Humanoid").Health = 0 end end)