What do you want to achieve? I want to teleport every player to the chosen map’s spawn.
What is the issue? I’m trying to loop through the players but it won’t work.
What solutions have you tried so far? I can’t think of any other way to do this.
This is a ServerScript:
--// Variables \\--
local RP = game:GetService("ReplicatedStorage")
local Maps = RP:WaitForChild("Maps")
local player = game.Players:GetPlayers()
local intermissionTime = 10
while true do
wait(intermissionTime)
local randomMap = math.random(1,1)
if randomMap == 1 then -- Chosen desert
print("desert chosen")
local map = Maps.Desert:Clone()
map.Parent = game.Workspace
for i = 1,#player do
print(player[i].Name)
local char = player[i].Character
char.HumanoidRootPart.Position = map.Spawn.Position
end
end
end
for i = 1,#player do
print(player[i].Name)
local char = player[i].Character
char.HumanoidRootPart.Position = map.Spawn.Position
end
With this:
for _, Player in pairs(game.Players:GetPlayers()) do
local char = Player.Character
if char then
char.HumanoidRootPart.Position = map.Spawn.Position
end
end