Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help Me On This SelfDestructOnDeath?

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

✓ Accepted answer

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)

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

1 comment

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 :/

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

2 comments

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 :/

0

Oh, sorry. I'll check on that.

This discussion is preserved as it was. New answers, comments, and votes are closed.