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

Very simple script has a problem?

I'm trying to clone a copy of my car into workspace again if it is driven off the baseplate, or even removed. When I tested, this didn't work.

lighting = game.Lighting
carcopy = lighting.CarCopy
car = game.Workspace.Car
workspace = game.Workspace

while true do
	wait(1)
	if car.Parent ~= workspace then
		carcopy:Clone()
	elseif car.Parent == workspace then
		print("Car still in workspace")
	end
	wait(1)
end

2 comments

0

You need to tell us what's going wrong, and what you're trying to do. Otherwise, it's unlikely we can fully help you.

0

There, updated.

3 answers

✓ Accepted answer

I've had this same problem too, try this instead;

local car = game.Workspace.Car:Clone() --This will clone the Car [As an extra copy]

while wait(1) do --This will repeat waiting 1 second(s) and doing the code below
if not game.Workspace:FindFirstChild("Car", true) then --If not script finds 'Car' within Workspace then
local newCar = car:Clone() --This will clone the Extra car
newCar.Parent = game.Workspace --Parent it to the Workspace
newCar:MakeJoints() --And make the Joints for it
end --This ends the code block for the 'if' statement
end --This ends the code block for the 'while true do end' loop

If this code does not work, or it is not complying with what your asking, then just let me know. :P Hope this helped!

2 comments

0

Thanks!

0

No problem! :)

The car that you cloned from Lighting, it's parent is nil and the script would've broke. Do this:

lighting = game.Lighting
carcopy = lighting.CarCopy
car = game.Workspace.Car
workspace = game.Workspace

while true do
    wait(1)
    if car.Parent ~= workspace then
        carcopy:Clone()
	carcopy.Name = "Car"
	carcopy.Parent = workspace
    elseif car.Parent == workspace then
        print("Car still in workspace")
    end
    wait(1)
end

This should work now.

Hahahah. LOL. When it's drove off the map, it's 'destroyed.' Thus, it's parent is nil and is locked. so;

lighting = game.Lighting
carcopy = lighting.CarCopy
car = game.Workspace.Car
workspace = game.Workspace

while true do
    if game.Workspace:FindFirstChild("Car") = false then --assuming it's called "Car"
        local c=carcopy:Clone()
	c.Name = "Car"
    elseif car.Parent == workspace then
        print("Car still in workspace")
	wait(1)    
end
    wait()
end

1 comment

0

Doesn't work.

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