Pretty nooby at scripting. I'm trying to make something where if it touches a PLAYER it explodes. Only problem is im dumb, and i need help because it will explode even if it touches a brick or the other npcs (zombies) that follow you. Thank you if you can help.
✓ ANSWER ACCEPTED
Help On touch of PLAYER explode?
1 answer
✓ Accepted answer
script.Parent.Touched:connect(function(h)
if h.Parent:FindFirstChildOfClass("Humanoid") then
local ex = Instance.new("Explosion", workspace)
ex.Position = script.Parent.Position
end
end)
put that in the brick.
steps:
script.Parent.Touched target the event
:connnect( connect a function to the event
function( we have no variable, so create one internally
h) parameters of the function: h
if h.Parent:FindFirstChildOfClass("Humanoid") then if the part is part of any npc/player, not caring about the name of the humanoid because of the "OfClass" part
local ex = define variable
Instance.new("Explosion", workspace) set "ex" to an instance parented in the workspace
ex.Position = script.Parent.Position set the position of the explosion to the position of the script's parent
end close off the if
end close off the function
) close off the connection
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks :)