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

help with making an acid tank?

Asked by
3x6x0 0
9 years ago

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

0
e.e i dont wanna buy stuff 3x6x0 0 — 9y

3 answers

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

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) --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.

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!
Ad
Log in to vote
0
Answered by
Wutras 294 Moderation Voter
9 years ago
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 
0
If this doesn't work then the character variable most likely not existing or a wrong object. Wutras 294 — 9y
Log in to vote
-1
Answered by
Uglypoe 557 Donator Moderation Voter
9 years ago

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)

Answer this question