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

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

Asked by 3 years ago
Edited 3 years ago

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
0
And yes, I tried both Destroy and Remove. DayLighter_1995 8 — 3y
0
I'll check back tomorrow if there is any help, anything helps. DayLighter_1995 8 — 3y
0
Of course nothing is happening, you never break out of the loops so the thread is held.  Ziffixture 6913 — 3y
0
Forgot to do that ziff DayLighter_1995 8 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)
0
connect is deceprated use :Connect sayer80 457 — 3y
0
:remove and :Remove is also deprecated use :Destroy() sayer80 457 — 3y
0
:remove() just sets the parent to nil and not actually destroys it sayer80 457 — 3y
0
I used destroy DayLighter_1995 8 — 3y
Ad

Answer this question