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

Why is my health not going to zero when touching a part with my script?

Asked by 4 years ago

Im trying to make a death brick but when I step on it nothing happens, here's the code:

local lava = game.Workspace.Lava
fuction OnTouch(Lava)
local human = lava.parent:FindFirstChild("Humanoid")
if human ~= nil then 
human.MaxHealth = 0
end
end
script.parent.touched:Connect(function(Ontouch))

and could someone also explain to me why there needs to be two ends?

2 answers

Log in to vote
0
Answered by 4 years ago

It is not working for a couple reasons, you wrote "fuction" instead of function. Also on your last line you only have to say "script.Parent.Touched:Connect(OnTouch)" Because you are calling a function instead of running an argument. Lastly Lua is case sensitive so "script.parent" has to be "script.Parent". So your code would be:

local lava = game.Workspace.Lava
    function OnTouch(Lava)
        local human = lava.Parent:FindFirstChild("Humanoid")
        if human ~= nil then
    human.Health = 0
    end
end
script.Parent.Touched:Connect(OnTouch)
0
Thank you! I fixed the errors but my character still doesn't die when touching the brick. mikechris333 10 — 4y
0
Did you change MaxHealth to Health? DesertusX 435 — 4y
0
yup mikechris333 10 — 4y
0
I fixed it mikechris333 10 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

first of all you have a few mistakes here and there you writed fuction instead fo function and you missed some capitales. There needs to be 2 end to close functions at line 2 and a normal end

    local lava = game.Workspace.Lava
    fuction OnTouch(Lava)
    local human = lava.Parent:FindFirstChild("Humanoid")
    if human ~= nil then
    human.Health = 0
    end
    end)
    script.Parent.Touched:Connect(function(Ontouch))

hope this helps

0
I tried this but the block still doesn't do anything :( mikechris333 10 — 4y

Answer this question