This Is a Map for one of my games
How would I make this so only 1 player spawns on each pole if they are in the “Playing” team?
I have looked around the Forums and cant seem to find a way to do this
I was this to work like plates of fate of something like that.
Add an attribute to each pole named “Taken” and set it as a boolean.
Each round, reset the values and loop through the players. For every player, assign them a non-taken pole and set the attribute to true
.
1 Like
Here’s how I would approach this
local gameSpawns = game:GetService("Workspace"):WaitForChild("Spawns"):GetChildren() -- Change to your actual folder of spawns
local Players = game:GetService("Players")
local rnd = Random.new()
local function teleportPlayersToSpawns()
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
local assignedPole = nil
for _, spawnPoint in pairs(gameSpawns) do
if spawnPoint:GetAttribute("Taken") ~= true then
assignedPole = spawnPoint
spawnPoint:SetAttribute("Taken", true)
break
end
end
if assignedPole then
if player.Character.PrimaryPart then
player.Character:SetPrimaryPartCFrame(assignedPole.CFrame)
end
end
end
end
end
Assuming you want the teleportation to be random, you need only source an array of the poles, select a pole at random, remove that pole from the array, then teleport the player in iteration to that pole:
local function teleport(players: {Player})
local poles = Poles:GetChildren()
for _, player in players do
local character = player.Character
if not character then
continue
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health <= 0 then
continue
end
local randomIndex = math.random(#poles)
local randomPole = table.remove(poles, randomIndex)
local cframe = CFrame.new(randomPole.Position)
character:PivotTo(cframe)
end
end
I think you replied to the wrong post