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

Very simple script has a problem?

Asked by
Relatch 550 Moderation Voter
9 years ago

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
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. RoboFrog 400 — 9y
0
There, updated. Relatch 550 — 9y

3 answers

Log in to vote
1
Answered by 9 years ago

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!

0
Thanks! Relatch 550 — 9y
0
No problem! :) TheeDeathCaster 2368 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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.

Log in to vote
-2
Answered by
drahsid5 250 Moderation Voter
9 years ago

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

0
Doesn't work. Relatch 550 — 9y

Answer this question