Teleporting players to wrong position?

So I’m making a teleporting system where players got assigned to a specific position that will have a queue for them. For example Spawn1 will get assigned and then Spawn2 will got assigned after and so on.

The issue is that the player gets teleported to the spawn1 only even though the output says that’s player got assigned to different position.

Code:

local rm = game.ReplicatedStorage:FindFirstChild("trm")
local cdo = game.ReplicatedStorage:FindFirstChild("cdo")
local gui = script.Parent.Intermission
local label = gui.TimeLabel
local ReplicateStorage = game:GetService("ReplicatedStorage")
local prep = ReplicateStorage.prep
local player = game.Players.LocalPlayer

local spawnQueue = {}
local playerSpawnMap = {}

rm.OnClientEvent:Connect(function(timer)
	local timers = timer 
	if timer == 0 then
		label.Visible = false
		prep.OnClientEvent:Connect(function(map)
			local spawnPositions = {}
			for i = 1, 5 do 
				local spawnName = "Spawn" .. i
				for _,child in pairs(map:GetChildren()) do
					if child.Name == spawnName and child:IsA("BasePart") then
						table.insert(spawnPositions, child.Position)
					end
				end
			end
			-- Assign spawns to players
			local players = game.Players:GetPlayers()
			for i = 1, #players do
				local playerSpawn = spawnPositions[(i-1) % #spawnPositions + 1]
				playerSpawnMap[players[i]] = playerSpawn
				print(players[i].Name .. " will spawn at " .. tostring(playerSpawn))
			end
		
			-- Teleport players to their assigned spawn positions
			for _,plr in pairs(players) do
				wait(1)
				plr.Character.HumanoidRootPart.CFrame = CFrame.new(playerSpawnMap[plr])
				print("Teleported " .. plr.Name .. " to " .. tostring(playerSpawnMap[plr]))
			end
		end)
	else
		label.Visible = true		
		local str = tostring(timers)
		label.Text = "Intermission : ".. str 
		print("Intermission: " .. str)
	end					
end)

cdo.OnClientEvent:Connect(function()
	cdo:FireServer()
end)

I think the best way to do this after selecting the spawn location you then fire a server event and on the server set the player.RespawnLocation to the spawn you just chose. That should make sure it always goes to the correct spawn.

I think I explain a little bit wrong. I didn’t want to set a spawn for a player, Imagine a racing game like Mario Kart. When a game starts player got teleported to the map and waits for the game to start. that’s what I’m trying to do, I’m not trying to set a spawn for a player, just assigning a point to teleport to and wait for the game to start.


This is an image, if you don’t understand . Players will get teleport to point1 , point2 and so on.

Yeah I guess the confusion was you using the terms Spawn1 and Spawn2 so I assumed they were SpawnLocations. You might try letting the server teleport all the players to their new spawn locations instead of the client. Maybe the clients are all setting their location to the first Spawn and overriding your other clients. Maybe GetPlayers() has a different order on each client…just something to check.

1 Like

Fixed the problem right away, thank you bro.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.