I have a button that explodes and regenerates a model it works fine but after multiple uses the model’s Parent is set to nil and the script does not spawn the model into workspace here is my script:
local button = game.Workspace.Explody
local smallship = game.Workspace.smallship
local copy = game.ReplicatedStorage.smallship:Clone()
local debounce = false
button.Touched:Connect(function(hit)
if not debounce then
debounce = true
local ex = Instance.new("Explosion")
ex.Parent = game.Workspace.smallship
ex.Position = Vector3.new(-135, 9.5, -35)
ex.BlastRadius = 50
ex.DestroyJointRadiusPercent = 0.5
button.CanCollide = false
button.Transparency = 1
wait(16)
wait(0.1)
game.Workspace.smallship.Parent = nil
game.Workspace.smallshipspot.Roof.CanCollide = false
copy.Parent = game.Workspace
copy:MoveTo(Vector3.new(-135, 9.5, -35))
wait(2)
game.Workspace.smallshipspot.Roof.CanCollide = true
button.CanCollide = true
button.Transparency = 0
wait(3)
debounce = false
end
end)
The error I get says this:
smallship is not a valid member of Workspace "Workspace"
I set the parent of the new model to workspace before I set the parent of the previous model so I don’t know whats causing this to happen.