Ok, I don't have a weak pc or something, but this crashes my game everytime it runs:
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player, NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
local location = math.random(1,7)
local spawnlocations = game.Workspace.World.SpawnLocations
if location == 1 then
car:SetPrimaryPartCFrame(spawnlocations.part)
end
if location == 2 then
car:SetPrimaryPartCFrame(spawnlocations.part1)
end
if location == 3 then
car:SetPrimaryPartCFrame(spawnlocations.part2)
end
if location == 4 then
car:SetPrimaryPartCFrame(spawnlocations.part3)
end
if location == 5 then
car:SetPrimaryPartCFrame(spawnlocations.part4)
end
if location == 6 then
car:SetPrimaryPartCFrame(spawnlocations.part5)
end
if location == 7 then
car:SetPrimaryPartCFrame(spawnlocations.part6)
end
car.Parent = workspace
car:MakeJoints()
car.Name = player.name.."'s "..NameOfCar
car.Wheels.RR.ChildAdded:Connect(function(child)
if child.Name == "Smoke" then
repeat
if child.Rate ~= 0 then
cash.Value = cash.Value + 10
end
until car == nil
end
end)

1 comment
you can also shorten the code if you use tostring(location) for "part1" and replace the number.