Hello!
I am trying to make simple AI cars like the first screenshot, that will go in two directions and when cars will touch the red part the cars will be destroyed, but I have some problems with the script and I don’t know why it happens, in the console I don’t get any errors.
1: When you start, the cars clone well like the second screenshot but after a few minutes it starts to look like the third screenshot.
2: Only the same cars are cloned, there are more cars like police, trucks and others but only those appear.
Script:
local Cars = game.ReplicatedStorage.Cars
local RandomCar = Cars:GetChildren()[math.random(1, #Cars:GetChildren())]
local NewCar = RandomCar:Clone()
local Cars2 = game.ReplicatedStorage.Cars2
local RandomCar2 = Cars2:GetChildren()[math.random(1, #Cars2:GetChildren())]
local NewCar2 = RandomCar2:Clone()
while wait(5) do
RandomCar:Clone().Parent = game.Workspace.Cars
RandomCar2:Clone().Parent = game.Workspace.Cars
wait(10)
end
game.Workspace.Part:Connect(function(hit)
if hit.Parent.Parent.Name == "Car1" or hit.Parent.Parent.Name == "Car2" or hit.Parent.Parent.Name == "Car3" then
hit.Parent.Parent:Destroy()
end
end)