Code seems to just stop after this specific line

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m currently trying to refine and bug fix some code I wrote a few months ago, it’s a car spawning system.

  1. What is the issue? Include screenshots / videos if possible!

After a specific line, the code does not run anymore, and I’m not sure why.

The specific line that prints (last line that prints)

local success, err = pcall(function()
		Money:SetAsync(Player.UserId, newcash)
	end)
	if success then
		print("Success!")


			local success, err = pcall(function()
					CarsOwned:SetAsync(Player.UserId .. Vehichle, true)
			end)

			if success then
				print("Success!")
			end
				print("Checking which vehicle")

full code for the area that does not run
(Heads up, it’s a lot of code)

			print("Checking which vehicle")
--▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂--
			--▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂--
		if Vehichle == "FordExplorer" then
								Player.PlayerGui.CarSpawn.FordExplorerFrame.Purchasebutton.Text = "Vehicle purchased and spawned!"
								wait(2)
								Player.PlayerGui.CarSpawn.FordExplorerFrame.Purchasebutton.Text = "Spawn"

									local clone = game.ReplicatedStorage.explorer:Clone()
									--clone:SetPrimaryPartCFrame(	CFrame.new(69, 136, -2819))
									--clone.Parent = game.Workspace
									--clone:SetPrimaryPartCFrame(	CFrame.new(69, 136, -2819))
									--print(clone.Parent)
									--print("Yeet")



										--------------- VEHICLE SPAWNING CONTAINER START----------------------------
										-- Numeric for-loop example
										local children = workspace.CarSpawns:GetChildren()
										for i, child in ipairs(children) do
											if Foundspawn == false or Foundspawn == nil then
												print("AYO")
												local function GetTouchingParts(part)
													local connection = part.Touched:Connect(function() end)
													local results = part:GetTouchingParts()
													connection:Disconnect()
													return results
												end

												local results = GetTouchingParts(child)
												print(#results) --> 1
												print(results)

												if #results >= 1 then
													print("TOuched")
													Foundspawn = false
												elseif #results == 0 then
													print("Not touching anything")
													Foundspawn = true
													carspawnCframe = child.CFrame
													print(carspawnCframe)
													print(child.CFrame)
												end
												print("AYO")
												--local child = children[i]
												print(child.Name .. " is child number " .. i)
												print("AHHHHHHH")

											elseif Foundspawn == true then
												--clone:SetPrimaryPartCFrame(	CFrame.new(carspawnCframe))
												clone:SetPrimaryPartCFrame(carspawnCframe)
												clone.Parent = game.Workspace
												local Character = Player.Character or Player.CharacterAdded:Wait()
												Character.HumanoidRootPart.CFrame = clone.Body.ok.Body.fRONTLEFTBRICK.CFrame
												Foundspawn = nil
												carspawnCframe = nil
											end

										end
										--------------- VEHICLE SPAWNING CONTAINER END----------------------------




								Player.PlayerGui.CarSpawn.FordExplorerFrame.Visible = false
					Player.PlayerGui.CarSpawn.F150Frame.Visible = false
					
--▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂--
				--▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂--
		elseif Vehichle == "F150" then
							Player.PlayerGui.CarSpawn.F150Frame.Purchasebutton.Text = "Vehicle purchased and spawned!"
							wait(2)
							Player.PlayerGui.CarSpawn.F150Frame.Purchasebutton.Text = "Spawn"

								local clone = game.ReplicatedStorage.F150:Clone()
								---clone:SetPrimaryPartCFrame(	CFrame.new(69, 136, -2819))
								---clone.Parent = game.Workspace
								---clone:SetPrimaryPartCFrame(	CFrame.new(69, 136, -2819))
								print(clone.Parent)
								print("Yeet")




									--------------- VEHICLE SPAWNING CONTAINER START (f150)----------------------------
									-- Numeric for-loop example
									local children = workspace.CarSpawns:GetChildren()
									for i, child in ipairs(children) do
										if Foundspawn == false or Foundspawn == nil then
											print("AYO")
											local function GetTouchingParts(part)
												local connection = part.Touched:Connect(function() end)
												local results = part:GetTouchingParts()
												connection:Disconnect()
												return results
											end

											local results = GetTouchingParts(child)
											print(#results) --> 1
											print(results)

											if #results >= 1 then
												print("TOuched")
												Foundspawn = false
											elseif #results == 0 then
												print("Not touching anything")
												Foundspawn = true
												carspawnCframe = child.CFrame
												print(carspawnCframe)
												print(child.CFrame)
											end
											print("AYO")
											--local child = children[i]
											print(child.Name .. " is child number " .. i)
											print("AHHHHHHH")

										elseif Foundspawn == true then
											--clone:SetPrimaryPartCFrame(	CFrame.new(carspawnCframe))
											clone:SetPrimaryPartCFrame(carspawnCframe)
											clone.Parent = game.Workspace
											local Character = Player.Character or Player.CharacterAdded:Wait()
											Character.HumanoidRootPart.CFrame = clone.Body.car.Carmodel.Body.ModelR.SPMeshPart.fRONTLEFTBRICK.CFrame
											Foundspawn = nil
											carspawnCframe = nil
										end

									end
									--------------- VEHICLE SPAWNING CONTAINER END(f150)----------------------------




								Player.PlayerGui.CarSpawn.FordExplorerFrame.Visible = false
								Player.PlayerGui.CarSpawn.F150Frame.Visible = false
								end
--▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂--
--▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂--
		elseif Vehichle == "Nissan" then
								Player.PlayerGui.CarSpawn.NissanFrame.Purchasebutton.Text = "Vehicle purchased and spawned!"
								wait(2)
								Player.PlayerGui.CarSpawn.NissanFrame.Purchasebutton.Text = "Spawn"

								local clone = game.ReplicatedStorage.Nissan:Clone()
								---clone:SetPrimaryPartCFrame(	CFrame.new(69, 136, -2819))
								---clone.Parent = game.Workspace
								---clone:SetPrimaryPartCFrame(	CFrame.new(69, 136, -2819))
								print(clone.Parent)
								print("Yeet")




								--------------- VEHICLE SPAWNING CONTAINER START (f150)----------------------------
								-- Numeric for-loop example
								local children = workspace.CarSpawns:GetChildren()
								for i, child in ipairs(children) do
									if Foundspawn == false or Foundspawn == nil then
										print("AYO")
										local function GetTouchingParts(part)
											local connection = part.Touched:Connect(function() end)
											local results = part:GetTouchingParts()
											connection:Disconnect()
											return results
										end

										local results = GetTouchingParts(child)
										print(#results) --> 1
										print(results)

										if #results >= 1 then
											print("TOuched")
											Foundspawn = false
										elseif #results == 0 then
											print("Not touching anything")
											Foundspawn = true
											carspawnCframe = child.CFrame
											print(carspawnCframe)
											print(child.CFrame)
										end
										print("AYO")
										--local child = children[i]
										print(child.Name .. " is child number " .. i)
										print("AHHHHHHH")

									elseif Foundspawn == true then
										--clone:SetPrimaryPartCFrame(	CFrame.new(carspawnCframe))
										clone:SetPrimaryPartCFrame(carspawnCframe)
										clone.Parent = game.Workspace
										local Character = Player.Character or Player.CharacterAdded:Wait()
										Character.HumanoidRootPart.CFrame = clone.Body.carmodel.Body.fRONTLEFTBRICK.CFrame
										Foundspawn = nil
										carspawnCframe = nil
									end

								end
								--------------- VEHICLE SPAWNING CONTAINER END(f150)----------------------------




								Player.PlayerGui.CarSpawn.NissanFrame.Visible = false
								Player.PlayerGui.CarSpawn.NissanFrame.Visible = false
		
			else
				print("what")
			end
-- end marking the check if cash is greater or less
		else
			print("What")
		end

Lastly, ignore all of the random prints :sweat_smile: , they were just there for detection, and actually is part of the reason that I know this part isn’t working.

Thanks to anyone who helps!

any errors in the output? may i see what is the Vehichle variable just incase you are concatenating .. a string with a string(not an instance)
ex: "545353" .."Humvee"

local success, err = pcall(function()
					CarsOwned:SetAsync(Player.UserId .. Vehichle, true)
			end)

			if success then
1 Like

No errors in the output after that, and let me show you the part where the Vehicle variable is set:

for i,v in pairs(VehicleNames) do
		if Vehichle == v then
			print("Match")
			print(v)
			print(Vehichle)
			 vehname = v

^ Basically Checks a table and matches the table value to the vehicle value that was passed (exploit prevention)

local VehicleNames = {"FordExplorer", "F150", "Nissan"}

^ thats the table


local function spawncar(player, Name)
	if Name == "FordExplorer" then
		--local clone = game.ReplicatedStorage.explorer:Clone()
		--clone.Parent = game.Workspace
		--local seat = clone.DriveSeat
		--player.Character.HumanoidRootPart.CFrame = clone.Body.ok.Body.fRONTLEFTBRICK.CFrame
		----clone.PrimaryPart.Position = Vector3.new(69.436, 137.113, -2818.217)
		--player.PlayerGui.CarSpawn.FordExplorerFrame.Visible = false
		--player.PlayerGui.CarSpawn.Enabled = false
		--clone:SetPrimaryPartCFrame(CFrame.new(69.436, 137.113, -2818.217))

		
		
		MoneyManager.Vehicle(player, Name)

	elseif Name == "F150" then
		--local clone = game.ReplicatedStorage.F150:Clone()
		--clone.Parent = game.Workspace
		--local seat = clone.DriveSeat
		--player.Character.HumanoidRootPart.CFrame = clone.Body.car.Carmodel.Body.ModelR.SPMeshPart.fRONTLEFTBRICK.CFrame
		----clone.PrimaryPart.Position = Vector3.new(69.436, 137.113, -2818.217)
		--player.PlayerGui.CarSpawn.FordExplorerFrame.Visible = false
		--player.PlayerGui.CarSpawn.Enabled = false
		--clone:SetPrimaryPartCFrame(CFrame.new(69.436, 137.113, -2818.217))

		
		
		MoneyManager.Vehicle(player, Name)
	elseif Name == "Nissan" then
		MoneyManager.Vehicle(player,Name)
	elseif Name == "AR" then
		MoneyManager.Weapon(player, Name)
	elseif Name == "Deagle" then
		MoneyManager.Weapon(player, Name)
	end
	
end

^ Everything commented out is deprecated, and that basically recives a signal from the client asking for the car, then it sends to the script that I’m having trouble with.

1 Like

I FINALLY FOUND THE ISSUE!

Basically, it’s as simple as one ‘end’.

Throughout my script each ending of a vehicle spawning has 2 'end’s at the end of it:

	Character.HumanoidRootPart.CFrame = clone.Body.carmodel.Body.fRONTLEFTBRICK.CFrame
										Foundspawn = nil
										carspawnCframe = nil
									end

								end

Turns out the one before the Nissan had three ends, ending the entire function of spawning a car. So any care beyond the F150, would not spawn since the F150’s code, completely shuts down the spawning function. Good grief this caused wayy too much stress.

1 Like