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

How do I make a OnClick function kill a zombie?

I am trying to make a button that is connected to the zombie's chest or something that kills the zombie. The zombie doesn't have a name to prevent the name from showing, but there is a humanoid part called "Zombie" if that could be used. Here is the script:

function OnClick()
	script.Parent.Parent.health = 0
end

I am still new at scripting, so please go easy on me. :)

1 comment

0

You need to connect it to an event.

1 answer

Like hiimgoodpack said, you need to connect it to and event.

All the events for click detectors are here: http://wiki.roblox.com/index.php?title=API:Class/ClickDetector

If this is a SurfaceGui, then all events for text buttons are here: http://wiki.roblox.com/index.php?title=API:Class/TextButton

Here is a script for if you are using a text button.

function onClicked()
	script.Parent.Parent:FindFirstChild("Humanoid").Health = 0 --this is considering that the parent you are addressing is the model.
end

script.Parent.MouseButton1Click:connect(onClicked) 

--this is untested

Accept the answer if it helped

4 comments

0

I'm not sure what the problem is with it. The click detector doesn't fire the script, and the output doesn't report any problems.

0

script.Parent.MouseButton1Click:connect(onClicked) This event is wrong this one should be used for Guis not for clickdetectors so instead use script.Parent.ClickDetector.MouseClick:connect(onClicked)

0

lol

0

I'd recommend studying events in the object browser of studio. Also, I know it makes me sound like a hypocrite because I'm having a hard time switching too but use :Connect instead of :connect as it is deprecated.

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