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

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

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

✓ Accepted answer

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)

4 comments

0

Thank you! I fixed the errors but my character still doesn't die when touching the brick.

0

Did you change MaxHealth to Health?

0

yup

0

I fixed it

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

1 comment

0

I tried this but the block still doesn't do anything :(

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