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)