Weird differences between spawn functions

Hello
I haveth an issue. Yah see I’m spawning in cars and the players in their own cars.

However see this script:

Spawn Function used First
function chooseRandomSpawn(tab, player, team)
	--// in the maps there are folders full of parts that indicate where spawns will be, this will loop through them and spawn a player at them
	--// when the player is spawned in, set the transparency to 1 to indicate that a plr was spawned
	for i, part in pairs (tab) do
		if part.Transparency == 0 then
			if team then
				if part.Name == tostring(player.Team) then
					part.Transparency = 1
					return part
				end
			else
				part.Transparency = 1
				return part
			end
		end
	end
end

function core.spawnPlayers(map, mode)
	mode = mode == "CONTROL" and "TDM" or mode --damn
	local points = map.Spawns[mode]:GetChildren()
	for i, part in pairs (points) do
		part.Transparency = 0
	end
	for i, player in pairs (game.Players:GetPlayers()) do
		local car, gun, vVisual, wVisual = game.ReplicatedStorage.getPlayerVehicle:Invoke(player) --// we need to get the current car, and current visuals so we can customize the car upon spawning
		car = game.ServerStorage.Cars:FindFirstChild(car)
		--// Spawn Vehicle
		if car then
			local sP = chooseRandomSpawn(points, player, (mode == "TDM" and true or false)).Position
			car = car:Clone()
			car:MoveTo(sP + Vector3.new(0, 0, 0))
			wait(0.1)
			funcs.customize(car, vVisual, false) --// args: object, visual, isGun (false = car, true = weapon .. duh)
			car.Parent = player.Character
			wait() --allow for the car script to initialize
			player.Character:MoveTo(sP)
			--funcs.seatPlayer(player, car)
			player.Character.HumanoidRootPart.CFrame = car.VehicleSeat.CFrame
			car.VehicleSeat:Sit(player.Character.Humanoid)
			-- mount gun
			local gun = funcs.mountGun(gun, car, mode)
			
			if gun then
				funcs.customize(gun, wVisual, true) -- color the gun to its according skins and whatnot
				gun.Parent = car
				delay(1, function()
					gun.WeaponHandler.Disabled = false -- so the code can run for le gun
				end)
			end
		end
	end
	for i, part in pairs (points) do
		part.Transparency = 1
	end
end

That script doesn’t spawn the cars at the spawn points that I have put around my map. Instead player’s will find themselves under or out of bounds of the map.

And come to this respawn function inside the mode modules:

Respawn function in modes, that happens second, and everytime after
local function respawn()
	warn "Respawning!"
	for i, plr in pairs(deathDeb) do --resets the debounce
		if plr == player then
			table.remove(deathDeb, i)
			break
		end
	end
	local spawns = map.Spawns.FFA
	repeat wait() until player.Character.Parent == workspace
	for i, v in pairs (spawns:GetChildren()) do
	        if v.Transparency == 1 then
		        v.Transparency = 0
		        player.Character:MoveTo(v.Position)--// Spawn Vehicle
		        local car, gun, vVisual, wVisual = game.ReplicatedStorage.getPlayerVehicle:Invoke(player) --// we need to get the current car, and current visuals so we can customize the car upon spawning
			car = game.ServerStorage.Cars:FindFirstChild(car)
			if car then
				car = car:Clone()
				funcs.customize(car, vVisual, false) --// args: object, visual, directory (Cars, Weapons)
				car.Parent = player.Character
				-- mount gun
				local gun = funcs.mountGun(gun, car, "FFA")
				if gun then
			        	funcs.customize(gun, wVisual, true) -- color the gun to its according skins and whatnot
					gun.Parent = car
					delay(1, function()
						gun.WeaponHandler.Disabled = false -- so the code can run for le gun
					end)
				end
				car:MoveTo(player.Character.HumanoidRootPart.Position)
				player.Character.HumanoidRootPart.CFrame = car.VehicleSeat.CFrame
			end
			delay(5, function()
				wait(5)
				v.Transparency = 1
			end)
			return
		end
	end
end

See this function is more successful, but I don’t understand why.

Is it because of how the teleportation is set up? Player first, then car? I don’t really get this…

Did you already try spawning the cars a bit above the ground?

Yup, all spawn points are at least 5 studs above the ground.

Try parenting the car first, and then set it’s position to the spawn point. This is what I see is different from first spawn and the respawn. In the respawn code you parent the car first and then set it’s position, while on the first spawn you set the position first and then parent it.

Tried that, but it still does the same issue…

I’ll try moving the player first, then the car.

Changing the order actually helped, but thank you anyways for helping me!

1 Like