So I'm trying to make it that if a player or a humanoid touches a part, it will explode.
But it seems to only work once. If I try to touch the part again it will give me this error:
The Parent property of explosion is locked, current parent: NULL, new parent Torso
I know it has something to do with this part of the code:
local explosion = Instance.new("Explosion") explosion.BlastPressure = 100 explosion.BlastRadius = 6 explosion.DestroyJointRadiusPercent = 0 explosion.Parent = game.Workspace explosion.Position = script.Parent.Position hit.Parent.Humanoid:TakeDamage(50)
But I don't know what's wrong with it.
I've looked everywhere for an answer but I can't seem to find one that brings a solution to my problem. Explosions remove themselves in a few seconds so I know I don't need to remove it with the script. Please help. Thanks.
I'm pretty sure the reason is that the code is only being fired once, after the first explosion has exploded there is no other explosions left to explode. Assuming that the player has 100 health you would need to create 2 to kill it.
local explosion1 = Instance.new("Explosion") local explosion2 = Instance.new("Explosion") game:WaitForChild("Players").PlayerAdded:Connect(function(plr) -- plr now refers to the player game:WaitForChild("Workspace").CharacterAdded:Connect(function(char) -- char now refers to the character explosion1.BlastPressure = 100 explosion1.BlastRadius = 6 explosion1.DestroyJointRadiusPercent = 0 explosion1.Parent = game.Workspace explosion1.Position = script.Parent.Position hit.Parent.Humanoid:TakeDamage(50) if char.Humanoid.Health <= 50 then -- Player health should be below 50 or 50 from the other explosion, if this is true continue if not don't run the other explosion explosion2.BlastPressure = 100 explosion2.BlastRadius = 6 explosion2.DestroyJointRadiusPercent = 0 explosion2.Parent = game.Workspace explosion2.Position = script.Parent.Position hit.Parent.Humanoid:TakeDamage(50)
I am quite new to scripting and am pretty sure this can be compacted but should work none the less. Please tell me if it works!