How would I spawn each player at their own spawn point with their own kart

I am creating a game kind of like Mario kart. I would like the players to spawn in their own kart at their own location (The server size is 5 people).

I have tried everything I can, but nothing has worked :frowning:. If anyone can give me a heads up in a direction which might work, I would highly appreciate it.

I have already searched for this for a long time and have found no article on this topic.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

4 Likes

Try teleporting the cart to the position you want it in once the round starts, or store carts in rep storage and make a clone when the round starts.

3 Likes

I have already created a working round script that teleport karts and players, but the players have to run to their carts(because they spawn at a specific location), and I would like to have the carts spawned with their name, so that I can create a customizable feature later on. And also that the player Spawns on their specific kart

For the cart spawning with their name use a billboard GUI, for them to spawn on their cart just teleport them right above their carts seat when the round starts, maybe use a GUI to mask the effect.

3 Likes

Thank you, but the main problem is about spawing the players karts at a location e.g. spawn1 - spawn5. Because if i use math.random, some of the karts could overlap in each other

Oh, well in that case I would use a for loop to put them in their spot, something that adds 1 every time it runs and then I would name the spots “Spot1”, “Spot2”, etc. I would then tp the player to the Spot using concatenation, “TeleportCart(“whatever player/cart your teleporting”, Spot…v). I hope this makes sense, if it does not feel free to ask questions.

3 Likes

That makes sense and I feel like I am on the right trail, Thank you so much for your time. I will check if this works in the morning as it is late where I am

Np, it’s like 2:30 am for me so I’m gonna go to bed, tomorrow I will help if it does not work.

There is a function you can use to force a player to sit in a seat.

https://developer.roblox.com/en-us/api-reference/function/Seat/Sit

If you want to have a random list you can get all the players. Then yo would need to jumble the list with an algorithm. Then loop through the jumbled list and sit each humanoid in their respective seats

3 Likes

Script it to choose a random number and put one cart there. Then script it to choose a random number excluding the previous number chosen and put a cart there, repeat that a few times.

yeh, thats the thing, i haven’t been able to get rid of the previous number, do you know how to do it?

No, if I knew scripting then I would have just wrote the script for you.

alright, thanks for the heads up anyways

3 Likes

I have tried to script it but has not succeeded. Is it possible for you to give a quick example or even write part of the script. You do not have to though, and no pressure.

2 Likes

ok, I will attempt to give an example.

local Carts = game.ReplicatedStorage.Carts:GetChildren() --I would put the carts in a folder in rep storage, you can change this though.

local function TeleportCarts(Cart, Spot)
	--blah blah blah this function teleports Cart to Spot, I do not know much about your game so I cannot write it for you
end

local function TeleportPlayer(Player, Cart)
	--this would teleport the Player to their Cart.
end
for i = 1, #Carts, 1 do
	local NumString = tostring(i)
	TeleportCarts(game.ReplicatedStorage.Carts:FindFirstChild("Cart"..NumString), CFrame.new(0, 0, 0)) --change Cframe to location you want the carts to go to
	
	TeleportPlayer(game.ReplicatedStorage.Carts:FindFirstChild("Cart"..NumString).Owner.Value, game.ReplicatedStorage.Carts:FindFirstChild("Cart"..NumString)) --I would add a value into each cart saying who owned it.
end

--I did not test this, hope it helps though!

I am still confused, do you mind if you tell me what value it is? I used a string value and it errored. It said

ServerScriptService.Script:25: attempt to index nil with 'Owner'

Is this because i used the wrong value for ‘Owner’

I would highly appreciate it if you could even go out of your way to make it in studio and send it as a file. Or even to make a model for it

Did you put the string value in the car?

I cannot as I do not know much about the cars you are using/how the rest of your game works, sorry.

I have done what you have said but have run into a problem, it is saying that ‘Player’ is nil which means that I can’t teleport the player. I have checked by printing the player.Name and it has come up with nil

local Carts = game.ReplicatedStorage.Carts:GetChildren()

local function TeleportCarts(Cart, Spot)
	print("Teleport Carts")
	Cart.Parent = workspace.Carts
end

local function TeleportPlayer(Player, Cart)
	print("teleport Player")
	print(Player.Name)
	Player.Character.HumanoidRootPart.Position = CFrame.new(9, 8, 17)
end


game.Players.PlayerAdded:Connect(function()
	wait(15)
for i = 1, #Carts, 1 do
		local NumString = tostring(i)
		print("Cart"..NumString)
	TeleportCarts(game.ReplicatedStorage.Carts:FindFirstChild("Cart"..NumString), CFrame.new(9, 5, 17)) 
	TeleportPlayer(game.Workspace.Carts:FindFirstChild("Cart"..NumString).Owner.Value, game.Workspace.Carts:FindFirstChild("Cart"..NumString))
	end
end)

The output says
ServerScriptService.Script:18: attempt to index nil with ‘HumanoidRootPart’
and the print where I did (Player.Name) comes up with nil in the output
Any ideas why?