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 . 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!
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.
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.
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
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
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.
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.
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 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?