|
| 26 Feb 2015 05:01 PM |
I have a script that clones a model. Here's the script:
local clone1 = game.Workspace.glassPanes:Clone() local clone2 = game.Workspace.glass1:Clone() local clone3 = game.Workspace.glass2:Clone() clone1.Parent = workspace clone2.Parent = workspace clone3.Parent = workspace wait(5) clone1:Destroy() clone2:Destroy() clone3:Destroy()
The script works fine on the first try, but when it fires twice, it breaks and the output says:
The Parent property of glassPanes is locked, current parent: NULL, new parent workspace
Why is it breaking, and can anyone help me? |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Feb 2015 05:51 PM |
| Can you tell me where is this script located? |
|
|
| Report Abuse |
|
|
| |
|
doggy00
|
  |
| Joined: 11 Jan 2011 |
| Total Posts: 3571 |
|
|
| 26 Feb 2015 05:52 PM |
Wait, if a script is supposed to be repeated, doesn't it need an 'end' at the end?
Not an expert, but from what I've learned, that's a true fact. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 05:53 PM |
| I dont see any kind of loop in there. So I don't know what he means by firing it twice. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 05:55 PM |
| I mean like, if this was in a Touched function and when a player touches a brick with the script in it twice it'll fire twice |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 05:56 PM |
For example:
debounce = true
script.Parent.Touched:connect(function() if debounce == true then debounce = false local clone1 = game.Workspace.glassPanes:Clone() local clone2 = game.Workspace.glass1:Clone() local clone3 = game.Workspace.glass2:Clone() clone1.Parent = workspace clone2.Parent = workspace clone3.Parent = workspace wait(5) clone1:Destroy() clone2:Destroy() clone3:Destroy() debounce = true end)
|
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:00 PM |
YOUR TESTIMONY CONTRADICTS THE EVIDENCE! #PhoenixWright
You say that the script is in workspace, and what do I see? "script.Parent.Touched". Care to explain, "witness"? |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Feb 2015 06:05 PM |
THen how exactly does the script work?
I will not know unless you provide the code in full. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:06 PM |
alright
local p = game.Workspace.glassPanes:GetChildren() local g1 = game.Workspace.glass1:GetChildren() local g2 = game.Workspace.glass2:GetChildren() local clone1 = game.Workspace.glassPanes:Clone() local clone2 = game.Workspace.glass1:Clone() local clone3 = game.Workspace.glass2:Clone() local cp = clone1:GetChildren() local cg1 = clone2:GetChildren() local cg2 = clone3:GetChildren()
function changed() if script.Parent.Value == true then clone1.Parent = game.Workspace.glassPanes.Parent clone2.Parent = game.Workspace.glass1.Parent clone3.Parent = game.Workspace.glass2.Parent for i = 1, #p do p[i].Transparency = 1 p[i].CanCollide = false end for i = 1, #g1 do g1[i].Transparency = 1 g1[i].CanCollide = false end for i = 1, #g2 do g2[i].Transparency = 1 g2[i].CanCollide = false end for i = 1, #cp do cp[i].BackSurface = "Smooth" cp[i].BottomSurface = "Smooth" cp[i].FrontSurface = "Smooth" cp[i].LeftSurface = "Smooth" cp[i].RightSurface = "Smooth" cp[i].TopSurface = "Smooth" cp[i].Anchored = false end for i = 1, #cg1 do cg1[i].BackSurface = "Smooth" cg1[i].BottomSurface = "Smooth" cg1[i].FrontSurface = "Smooth" cg1[i].LeftSurface = "Smooth" cg1[i].RightSurface = "Smooth" cg1[i].TopSurface = "Smooth" cg1[i].Anchored = false end for i = 1, #cg2 do cg2[i].BackSurface = "Smooth" cg2[i].BottomSurface = "Smooth" cg2[i].FrontSurface = "Smooth" cg2[i].LeftSurface = "Smooth" cg2[i].RightSurface = "Smooth" cg2[i].TopSurface = "Smooth" cg2[i].Anchored = false end wait(0.5) local explode1 = Instance.new("Explosion") explode1.Position = game.Workspace.expos1.Position explode1.BlastRadius = 30 explode1.Parent = game.Workspace explode1.BlastPressure = 1999999 wait(0.5) local explode2 = Instance.new("Explosion") explode2.Position = game.Workspace.expos2.Position explode2.BlastRadius = 30 explode2.Parent = game.Workspace explode2.BlastPressure = 1999999 wait(0.5) local explode3 = Instance.new("Explosion") explode3.Position = game.Workspace.expos3.Position explode3.BlastRadius = 30 explode3.Parent = game.Workspace explode3.BlastPressure = 1999999 wait(0.5) local explode4 = Instance.new("Explosion") explode4.Position = game.Workspace.expos4.Position explode4.BlastRadius = 30 explode4.Parent = game.Workspace explode4.BlastPressure = 1999999 wait(0.5) local explode5 = Instance.new("Explosion") explode5.Position = game.Workspace.expos5.Position explode5.BlastRadius = 30 explode5.Parent = game.Workspace explode5.BlastPressure = 1999999 wait(0.5) local explode6 = Instance.new("Explosion") explode6.Position = game.Workspace.expos6.Position explode6.BlastRadius = 30 explode6.Parent = game.Workspace explode6.BlastPressure = 1999999 wait(0.5) local explode7 = Instance.new("Explosion") explode7.Position = game.Workspace.expos7.Position explode7.BlastRadius = 30 explode7.Parent = game.Workspace explode7.BlastPressure = 1999999 wait(0.5) local explode8 = Instance.new("Explosion") explode8.Position = game.Workspace.expos8.Position explode8.BlastRadius = 30 explode8.Parent = game.Workspace explode8.BlastPressure = 1999999 wait(0.5) local explode9 = Instance.new("Explosion") explode9.Position = game.Workspace.expos9.Position explode9.BlastRadius = 30 explode9.Parent = game.Workspace explode9.BlastPressure = 1999999 wait(0.5) local explode10 = Instance.new("Explosion") explode10.Position = game.Workspace.expos10.Position explode10.BlastRadius = 30 explode10.Parent = game.Workspace explode10.BlastPressure = 1999999 wait(0.5) local explode11 = Instance.new("Explosion") explode11.Position = game.Workspace.expos11.Position explode11.BlastRadius = 30 explode11.Parent = game.Workspace explode11.BlastPressure = 1999999 wait(0.5) local explode12 = Instance.new("Explosion") explode12.Position = game.Workspace.expos12.Position explode12.BlastRadius = 30 explode12.Parent = game.Workspace explode12.BlastPressure = 1999999 wait(11) clone1:Destroy() clone2:Destroy() clone3:Destroy() local lol = game.Workspace.glass1:GetChildren() local lol1 = game.Workspace.glass2:GetChildren() script.Parent.Value = false for i = 1, #p do if p[i].BrickColor == BrickColor.new("Bright blue") then p[i].Transparency = 0.5 p[i].CanCollide = true else p[i].Transparency = 0 p[i].CanCollide = true end end for a, lol in ipairs(lol) do lol.Transparency = 0.5 lol.Size = Vector3.new(8, 47, 11) lol.CanCollide = true end for a, lol1 in ipairs(lol1) do lol1.Transparency = 0.5 lol1.Size = Vector3.new(8, 47, 11) lol1.CanCollide = true end local spike3 = game.Workspace.fire:getChildren() for i = 1, #spike3 do spike3[i].Smoke.Enabled = false spike3[i].Fire.Enabled = false end local g = game.Workspace:GetChildren() for a, g in ipairs(g) do if g.ClassName == "Part" then local pie = (string.sub(g.Name, 1, 5)) if pie == "enemy" then if g.Position.X > -1000 then g:Destroy() end end end end game.Workspace.building.health.Value = 400 end end
game.Workspace.gameover.Changed:connect(changed) |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:09 PM |
NOW I SEE,
When you fire the function once, clone1, 2, and 3 is non-existant, because of the :Destroy() method! Therefore, it cannot be cloned again! This explains why, it breaks the second time! |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:10 PM |
| To be concise, you must move those variables INSIDE the function. So it creates the clone every time it fires! |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:11 PM |
| How would destroying a clone of a model affect future clones of the same model? I'm not destroying the original model, just the clone of the model. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:12 PM |
| Because when you fire it once, that clone does not exist anymore! |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:12 PM |
| Oh ok thanks for helping out |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:14 PM |
Why? Because those three variables are representing the clones. With destroying it by,
"clone1:Destroy() clone2:Destroy() clone3:Destroy()"
Therefore, you cannot destroy something that is already destroyed. That is where the problem lies. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:15 PM |
| You are welcome, glad to help out, good luck with whatever you're making with that cluster of explosions. xD |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:15 PM |
| I see why it works now. Since the clones are assigned outside the function, they only exist once, which is why it doesn't work. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2015 06:16 PM |
| It's a building that explodes but I have to clone the windows so they can be recovered when the building regens |
|
|
| Report Abuse |
|
|
doggy00
|
  |
| Joined: 11 Jan 2011 |
| Total Posts: 3571 |
|
| |
|