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

Help w/ function onTouched?

Asked by
FiredDusk 1466 Moderation Voter
9 years ago

When I touch the part, my body does not explode.

--Make players heads explode when touched part
leftleg = game.Workspace.Player:GetChildren()
explosion = Instance.new("Explosion")

function onTouched(player)
    player.leftleg = explosion



end

script.Parent.Touched:connect(onTouched)

2 answers

Log in to vote
5
Answered by 9 years ago
function onTouch(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local Char = hit.Parent
        local explosion = Instance.new("Explosion", Char.Head)
        explosion.Position = Char.Head.Position
    end
end

script.Parent.Touched:connect(onTouch)

Checks if what touched the Part is indeed a Player's character, then Instances an explosion into that character's head.

I have no idea how to do explosions though.

0
It does not make me explode FiredDusk 1466 — 9y
1
I don't know how to do explosions. bosswalrus 84 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

So what we would first do is make the function.

function explode(part)

end

Now we will make a variable to access the torso.

local torso = part.Parent:FindFirstChild("Torso')

We now need to make sure that Torso actually exists, using if ~= nil then.

if torso ~= nil then

Now we do the explosions.

local explosion = Instance.new("Explosion")
explosion.Parent = torso
explosion.Position = torso.Position

The Finished Script

function explode(part)
    local torso = part.Parent:FindFirstChild("Torso')
    if torso ~= nil then
        local explosion = Instance.new("Explosion")
        explosion.Parent = torso
        explosion.Position = torso.Position
    end
end

We do not need to worry about the health, because the explosion will kill them anyways.

Please accept if helped.

Thank you.

Answer this question