Why are players spawning outside of the map in my game? Is this roblox physics? I need to know asap

My game downhill rush is hitting popularity now.

There’s an issue though, when the game starts and players load into their carts, very rarely will 1 player glitch out and a death message will appear “Player fell out of the map”
This is an annoying issue.

I’ve experienced it and my character or camera was flung to the world border and glitched.

for each, player in pairs(players) do
	
		if player and player.Parent and player.Character and player.Character:FindFirstChild("Humanoid") and player.Character:FindFirstChild("Humanoid").Health > 0 then
			
			task.spawn(function()
				
				game.ReplicatedStorage.RemoteEvent:FireClient(player, {"Status", "Game in progress!"})

				game.ReplicatedStorage.RemoteEvent:FireClient(player, {"Effect", "CircleIn"})
			
				local cc =  require(script.Parent.Parent.Parent.PlayerHandler)[player].CartInventory["CurrentCart"]  or "Blocko"
				
				
				local Folder = game.ReplicatedStorage.Carts:FindFirstChild(cc)
				
				print(player.Name," will drive ",cc)
				local Cart = Folder[cc]:Clone()
				Cart.Parent = workspace.Carts
				task.wait(1)
				local ref = Cart:GetDescendants()
				for i,v in pairs(ref) do
					if v:IsA("BasePart") then
						v.Anchored = false
					end
				end
				Cart.PrimaryPart.Anchored = true
				table.clear(ref)
				local bv, ao = Instance.new("BodyVelocity", Cart.PrimaryPart),  Instance.new("BodyGyro", Cart.PrimaryPart)
				bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				bv.P = 20000
				bv.Velocity = Vector3.new(0,0,0)
				ao.MaxTorque = Vector3.new(100,90,50)

								
				Carts[Cart] = {
					["Pilot"] = player,
				} 			
				
				local tempcon = nil
				tempcon = Cart.AncestryChanged:Connect(function()
					wait(5)
					if Cart.Parent == nil then
						Carts[Cart] = Utility.GC(Carts[Cart])
						Carts[Cart] = nil
						warn(Utility.CountItemsInDict(Carts)," are the carts that remain!")
						tempcon:Disconnect()
						tempcon = nil
					end
				end)
				

				Cart:MoveTo( spawnpoints[each].Position + Vector3.new(0,10,0) ) 
				Cart:SetPrimaryPartCFrame( spawnpoints[each].CFrame * CFrame.new(0,Cart:GetExtentsSize().Y / 2,0) )
				Cart:SetPrimaryPartCFrame(Cart.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(180),0) )
				spawnpoints[each].Transparency = 1
				
				ao.CFrame = Cart.PrimaryPart.CFrame

				if player.Character then
				else
					return
				end
			
				local seat = nil
				repeat task.wait(.1) 
					if Cart.Parent == nil or Carts[Cart] == nil then
						break
					end
					print("Waiting for ",Cart," to load")
					seat = Cart:FindFirstChild("Seat")
				until Cart.PrimaryPart and seat
				player.Character:SetPrimaryPartCFrame(seat.CFrame*CFrame.new(0,15,0))
				player.Character.Humanoid.JumpPower = 0
				Cart.PrimaryPart.Anchored = true

				repeat task.wait(.1)
					if seat.Occupant then break end
					if player and player.Character and player.Character:FindFirstChild("Humanoid") then
					else
						return
						
					end
					if Cart.PrimaryPart == nil or player.Character == nil then return end
					if player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health == 0 then return end
					
					player.Character:SetPrimaryPartCFrame(seat.CFrame)
					seat.CanCollide = false
					Cart.PrimaryPart.Anchored = false
					local ref = player.Character:GetDescendants()
					for i,v in pairs(ref) do
						if v:IsA("BasePart") then
							v.CanCollide = false
						end
					end
					player.Character.Humanoid.HipHeight = 0
					table.clear(ref)
					task.wait(.5)
					if player.Parent == nil or player.Character == nil or player.Character:FindFirstChild("Humanoid") == nil then 
					return end
					
					seat:Sit(player.Character.Humanoid)

				until Cart.Parent == nil or seat.Occupant
				if Cart.Parent == nil then
					print(Cart," does not exist?? why")
					return
				end
			
				seat.CanCollide = true
				local con;con = seat:GetPropertyChangedSignal("Occupant"):Connect(function()
					con:Disconnect()
					if Cart.Parent and Cart:FindFirstChild("Seat") and Cart.Seat.Occupant == nil then
						task.wait(3)
						
						Cart:BreakJoints()
						game:GetService("Debris"):AddItem(Cart, 5)
					end
				end)
				
				local CartSkin, CartCosmetics = nil, nil
				local CartInfo = require(script.Parent.Parent.Parent.PlayerHandler)[player].CartInventory[tostring(cc)]
				if CartInfo then
				--	warn(CartInfo, "huh")
					local CurrentSkin = CartInfo["CurrentSkin"]
					CartSkin, CartCosmetics = CartInfo[CurrentSkin], CartInfo["Cosmetics"]
					
					local folder = game.ReplicatedStorage.Carts[Cart.Name]
					for cosmetic, val in pairs(CartCosmetics) do  -- no names for the cosmetics.
						local cosmetic = folder["Cosmetics"]:FindFirstChild(cosmetic)
						if cosmetic and CartCosmetics[cosmetic.Name] and table.find(CartCosmetics[cosmetic.Name], CurrentSkin) then
							local cf = Utility.GetObjectSpaceCFrame(folder[Cart.Name], folder["Cosmetics"][cosmetic.Name]) 
							cosmetic = cosmetic:Clone()
							cosmetic.Parent = Cart
							local x = cosmetic:GetDescendants() 
							for i,v in pairs(x) do
								if v:IsA("BasePart") then
									v.CanCollide = false
									v.Anchored = false
									v.CanQuery = false
								end
							end
							table.clear(x)
							cosmetic:SetPrimaryPartCFrame( Cart.PrimaryPart.CFrame * cf)
							local weld = Instance.new("WeldConstraint", cosmetic.PrimaryPart)
							weld.Part1 = Cart.PrimaryPart
							weld.Part0 = cosmetic.PrimaryPart
						
						end
					end
					
					for partname, values in pairs(CartSkin) do
						local part = Cart:FindFirstChild(partname, true)
						if part then
							part.Color = Color3.new(values["Color"][1], values["Color"][2], values["Color"][3])
							part.Material = Enum.Material[values["Material"]]
						end
					end
				else
				end
				-- colour their cart
				local HasBooster, HasBumper, HasHover
				local success, error = pcall(function()
					 HasBooster, HasBumper, HasHover = game.ReplicatedStorage.RemoteFunction:InvokeClient(player, {"ChoosePerks", Cart}) -- they choose perks for their cart name
				end)
				
				if not success then
					
					Cart:Destroy()
				end
				-- If they don't have any more coins to afford anything the function is returned.

--				warn(player.Name, " has booster? ", HasBooster, " has bumper? ", HasBumper, " has Hover? ",HasHover)
				-- yields	
	
				

				
				-- color em again
				if CartSkin then
					for partname, values in pairs(CartSkin) do
						local part = Cart:FindFirstChild(partname, true)
						if part then
							part.Color = Color3.new(values["Color"][1], values["Color"][2], values["Color"][3])
							part.Material = Enum.Material[values["Material"]]
						end
					end
				end
				task.spawn(function()
					wait(20)
					local pp = Cart.PrimaryPart
					local prevpos
					while game["Run Service"]:IsStudio() == false and Cart and Cart.Parent and pp and pp.Parent and Carts[Cart] and  Carts[Cart]["Pilot"] do
						prevpos = pp.Position
						wait(3)
						if pp.Parent and (prevpos - pp.Position).Magnitude < 200 and Carts[Cart] and Carts[Cart]["Pilot"] then
							
							for i = 1, 30 do
								task.wait(.25)
								
								if i == 30 and pp.Parent and (prevpos - pp.Position).Magnitude < 200 and Carts[Cart] and Carts[Cart]["Pilot"]  then
									game.ReplicatedStorage.RemoteEvent:FireClient(Carts[Cart]["Pilot"], {"Defeated", "GOT STUCK!"})
									--print(Carts[Cart]["Pilot"]," Is stuck and must be removed")
									
								else
									if (prevpos - pp.Position).Magnitude > 200  then
										break
									end
								end	
							end
						end

					end
				end)
			
				
				CartInfo, CartSkin, CartCosmetics =  nil, nil, nil 
				-- remove references
				HasBumper, HasBooster, HasHover = nil, nil, nil
				
			end)

		else
			if player then
				table.remove(players, table.find(players, player))
				print(player," removed from list! ",#players," so far")
				if player.Parent then
				player:LoadCharacter()
				end
			end
		end

	end

There’s a lot of code smell cause I was getting frustrated trying to get it to work.

The cart is initially anchored.
If I sit the player before I unanchor the cart then the player is stuck even if I unanchor the cart.
tbh idk what else to do.

This is very strange, I can’t explain it…

Not sure what could be going wrong here- maybe it is a misplaced spawnpoint?

1 Like

No. It is not a misplaced spawnpoint. The same spawnpoint has successfully put a player there only for like 3 rounds later it just flings a player into the void.
The next one it seems okay.

Players are being flung out of the map.