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

Help On touch of PLAYER explode?

Asked by 6 years ago

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.

1 answer

Log in to vote
0
Answered by 6 years ago
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

0
Thanks :) MarioGenci -5 — 6y
Ad

Answer this question