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

Parent property being locked, how do I fix this?

Asked by
Nep_Ryker 131
4 years ago
Edited 4 years ago

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.

0
Put more of your code in the post. Usually parents are locked because you call Destroy on an object. hiimgoodpack 2009 — 4y

1 answer

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
Also taking another look at the error, did you destroy the part that exploded? because if you did you would need to re-parent that explosion zomspi 541 — 4y
0
I used the touch event for it so it should run every time it gets touched. I also checked if it has a humanoid. And no the part that exploded is not destroyed. Also my goal is to make it explode every time I touch it. Nep_Ryker 131 — 4y
0
my suggestion would be to make an actual explosion in replicated storage and instead of explosion.Parent = game.Workspace do explosion:Clone():Clone().Parent = game.Workspace zomspi 541 — 4y
0
put it in replicated storage or something zomspi 541 — 4y
View all comments (8 more)
0
and then modify the script to use that explosion not Instance.new zomspi 541 — 4y
0
I tried that, the explosion destroys itself in ReplicatedStorage like it does if it was in Workspace. It also does this in ServerStorage. Nep_Ryker 131 — 4y
0
try doing it with 1 clone so explosion:Clone().Parent = game.Workspace zomspi 541 — 4y
0
also, workspace is quite a broad term, if the player is blowing up parent it to the player's Torso, if the part is blowing up, parent it to the part zomspi 541 — 4y
0
If I try to clone it, it will say that explosion doesn't exist in ReplicatedStorage Nep_Ryker 131 — 4y
0
did you put it in replciated storage? zomspi 541 — 4y
0
Yes Nep_Ryker 131 — 4y
0
idk then, as I said I am not the best at scripting zomspi 541 — 4y
Ad

Answer this question