You can write your topic however you want, but you need to answer these questions:
- 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.
- 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 , 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!