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

How do I make a OnClick function kill a zombie?

Asked by 6 years ago

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

0
You need to connect it to an event. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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

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. CaptainAlien132 225 — 6y
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) Timmerman73 85 — 6y
0
lol DaWarTekWizard 169 — 6y
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. DaWarTekWizard 169 — 6y
Ad

Answer this question