So I'm trying to write a function that spawns cars for people. It's set up like a flood escape elevator. People can enter and equip a car and when the elevator moves down, it spawns everyones cars. I have a table that when people equip a car it puts the cars name as a string value into the table. The table is called CarArray. I used a couple of prints. The strings show up in the table. But the cars still wont spawn. No errors are printed and every print shows except anything after:
if value == CarArray[1] then
Any mistakes that you can see? Formatting or syntax or anything wrong?
local function SpawnCar() --Spawns Car
local carHolder_forLoop = carHolder:GetChildren()
local carStep = 0
local spawnPose = St1.Value + Vector3.new(0,5,0)
repeat
carStep = carStep + 1
for i = 1, #carHolder_forLoop do
local value = carHolder_forLoop[i]
if carStep == 1 then
if value == CarArray[1] then
print("CarArray[1]")
local Clone = value:Clone()
Clone.Parent = game.Workspace
Clone:MoveTo(St1.Value + Vector3.new(0,5,0))
else
print("Not Value1")
end
elseif carStep == 2 then
if value == CarArray[2] then
local Clone = value:Clone()
Clone.Parent = game.Workspace
Clone:MoveTo(St2.Value + Vector3.new(0,5,0))
else
print("Not Value2")
end
elseif carStep == 3 then
if value == CarArray[3] then
local Clone = value:Clone()
Clone.Parent = game.Workspace
Clone:MoveTo(St3.Value + Vector3.new(0,5,0))
else
print("Not Value3")
end
elseif carStep == 4 then
if value == CarArray[4] then
local Clone = value:Clone()
Clone.Parent = game.Workspace
Clone:MoveTo(St4.Value + Vector3.new(0,5,0))
else
print("Not Value4")
end
end
end
until carStep == #CarArray or carStep == 4
end
carHolder is a folder in replicatedStorage that holds all of the car models. there is a local script in Starter gui that lets you equip a car and when you do it fires a remote event called "Equip". It sends the string value of the car [Its name is the string], and it says what what player equiped it so it know what spot to put it in CarArray, since the elevator only holds 4 player at a time but only needs 2 to start the race timer. Also if the player does not equip a car it selects a random car that they own so that what ranCar is.
CarArray Adding function:
equip.OnServerEvent:Connect(function(player, ranCar, plr_Name) --Deals with Car Equipping
if PlayerArray[1] == plr_Name then
CarArray[1] = ranCar
elseif PlayerArray[2] == plr_Name then
CarArray[2] = ranCar
elseif PlayerArray[3] == plr_Name then
CarArray[3] = ranCar
elseif PlayerArray[4] == plr_Name then
CarArray[4] = ranCar
end
end)

3 comments
See if you can do an else statement after all the elseif statements and print something. You should put it after the end on line 45 and properly indent to line it up with the elseif statements. If that prints then there must be something wrong with your if statements.
Added an else and print at the end. The print didn't print, it printed "Not Value1", and "Not Value2" 14x each. That's the amount of cars that the loop is sorting through for player1, and player2.
can you add the table insertion function you have? I have a few thoughts on how to make this more efficient, though to answer your problem, i'd need to see what the carHolder array is and how you're adding strings to the CarArray table