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

Why isn't my car deleting after spawning? (Answered by Ziffixture)

My Car Spawner works but it won't delete or anything I tried destroying it, using a part to destroy it, putting a script that is cloned that waits 10 seconds to remove it nothing worked.

It's like roblox "destroy" and "remove" feature is broken.

local RandomCar = math.random(1,4)

local Cars = game.ReplicatedStorage.Cars:GetChildren()

local debounce = false

while true do
	wait(5)
	for i,v in pairs(Cars) do
		
		local CarClone = v:Clone()

		CarClone.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") and not debounce then
				debounce = true
				hit.Parent.Humanoid.Health = 0
				script.HitSound:Play()
				wait(2)
				debounce = false
			end
		end)
		
		if RandomCar == 1 then
			CarClone.Parent = workspace.CarSpawnFolder
			CarClone.CFrame = workspace.CarPos1.CFrame
			
			while true do
				wait()
				for i= 1, 300 do
					CarClone.CFrame = CarClone.CFrame * CFrame.new(0,0,2)
					wait()
				end
			end
			
			wait(10)
			CarClone:Remove()
		else
			if RandomCar == 2 then
				CarClone.Parent = workspace.CarSpawnFolder
				CarClone.CFrame = workspace.CarPos2.CFrame
				
				while true do
					wait()
					for i= 1, 300 do
						CarClone.CFrame = CarClone.CFrame * CFrame.new(0,0,2)
						wait()
					end
				end
				
				wait(10)
				CarClone:Remove()
			else
				if RandomCar == 3 then
					CarClone.Parent = workspace.CarSpawnFolder
					CarClone.CFrame = workspace.CarPos1.CFrame
					
					while true do
						wait()
						for i= 1, 300 do
							CarClone.CFrame = CarClone.CFrame * CFrame.new(0,0,2)
							wait()
						end
					end
					
					wait(10)
					CarClone:Remove()
				else
					if RandomCar == 4 then
						CarClone.Parent = workspace.CarSpawnFolder
						CarClone.CFrame = workspace.CarPos2.CFrame
						
						while true do
							wait()
							for i= 1, 300 do
								CarClone.CFrame = CarClone.CFrame * CFrame.new(0,0,2)
								wait()
							end
						end
						
						wait(10)
						CarClone:Remove()
					end
				end
			end
		end
	end
end

4 comments

0

And yes, I tried both Destroy and Remove.

0

I'll check back tomorrow if there is any help, anything helps.

0

Of course nothing is happening, you never break out of the loops so the thread is held. 

0

Forgot to do that ziff

1 answer

Here's the clone script you wanted to see:

system = script.Parent

model = system.Station --

backup = model:Clone()

regen = system.Regen

model:remove()

function checkRegen()

	if regen.Value == 1 then

		model:remove()

		wait(1)

		model = backup:Clone()

		model.Parent = workspace

		model:MakeJoints()

	end

end

regen.Changed:connect(checkRegen)

4 comments

0

connect is deceprated use :Connect

0

:remove and :Remove is also deprecated use :Destroy()

0

:remove() just sets the parent to nil and not actually destroys it

0

I used destroy

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