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

Help Me On This SelfDestructOnDeath?

Asked by 9 years ago

Im making a Alien that when he dies he self destructs but not kill you but the block from the lighting won't teleport to workspace where the torso is here is the script.

TorsoPos = script.Parent.Torso
ExplosionDamageBlock = game.Lighting.ExplosionDamage

while wait(1) do
if script.Parent.Alien.Health < 1 then
ExplosionDamageBlock:clone().Parent = workspace
ExplosionDamageBlock.Position = TorsoPos.Position
Explosion = Instance.new("Explosion")
Explosion.BlastPressure = 10
Explosion.BlastRadius = 0
Explosion.DestroyJointRadiusPercent = 0
Explosion.Position = TorsoPos.Position
Explosion.Parent = script.Parent.Torso
    wait(5)
    script.Parent:remove()
end
end

3 answers

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

The error I found in this code:

TorsoPos = script.Parent.Torso
ExplosionDamageBlock = game.Lighting.ExplosionDamage

while wait(1) do
if script.Parent.Alien.Health < 1 then
ExplosionDamageBlock:clone().Parent = workspace -- All right, you've set that to workspace.
ExplosionDamageBlock.Position = TorsoPos.Position   -- Not all right, since you're referring back to the ExplosionDamageBlock variable (game.Lighting.ExplosionDamage), not its clone.

Perhaps use a local variable to distinguish which variable goes with which object:

ExpDmgBlck = ExplosionDamageBlock:clone()
ExpDmgBlck.Parent = workspace
ExpDmgBlck.Position = TorsoPos.Position

SIDE NOTE

What your script is doing while it is running is checking the Alien's health every second. This might affect and raise the amount of activity (lag) in a server. One of the solutions is to make the function fire when the humanoid is altered by using Changed() or Died() events:

script.Parent.Alien.Changed:connect(function (Health)
    if script.Parent.Alien.Health < 1 then
    --[[ Your function ]]
    end
  end)
  
script.Parent.Alien.Died:connect(function ()
    --[[ Your function, without the 'if' statement ]]
  end)
  
Ad
Log in to vote
-1
Answered by 9 years ago

You forgot to capitalize "Clone()" and "Remove()"

TorsoPos = script.Parent.Torso
ExplosionDamageBlock = game.Lighting.ExplosionDamage

while wait(1) do
if script.Parent.Alien.Health < 1 then
ExplosionDamageBlock:Clone().Parent = workspace
ExplosionDamageBlock.Position = TorsoPos.Position
Explosion = Instance.new("Explosion")
Explosion.BlastPressure = 10
Explosion.BlastRadius = 0
Explosion.DestroyJointRadiusPercent = 0
Explosion.Position = TorsoPos.Position
Explosion.Parent = script.Parent.Torso
    wait(5)
    script.Parent:Remove()
end
end

0
It doesn't work the clone does work without the caps it just that the ExplosionDamageBlock Is Not Going To The Position Of The Torso :/ Anthony9960 210 — 9y
Log in to vote
-1
Answered by
Relatch 550 Moderation Voter
9 years ago

You didn't capitalize Clone, and I wouldn't recommend you use remove.

TorsoPos = script.Parent.Torso
ExplosionDamageBlock = game.Lighting.ExplosionDamage

while wait(1) do
    if script.Parent.Alien.Humanoid.Health <= 0 then --I also see another problem, health is located inside the humanoid, not the object itself.

        ExplosionDamageBlock:Clone().Parent = game.Workspace
        ExplosionDamageBlock.Position = TorsoPos.Position
        Explosion = Instance.new("Explosion")
        Explosion.BlastPressure = 10
        Explosion.BlastRadius = 0
        Explosion.DestroyJointRadiusPercent = 0
        Explosion.Position = TorsoPos.Position
        Explosion.Parent = script.Parent.Torso
        wait(5)
        script.Parent:Destroy() --Changed to Destroy
    end
end
0
Lol The Humanoid Name Is Alien :o and It doesn't work the clone does work without the caps it just that the ExplosionDamageBlock Is Not Going To The Position Of The Torso :/ Anthony9960 210 — 9y
0
Oh, sorry. I'll check on that. Relatch 550 — 9y

Answer this question