So I'm making a minigame game, and I'm using a pickmap function to randomly pick a minigame. But for some reason it won't work. Here's the script:
local minPlayers = 2
local replicatedStorage = game:GetService("ReplicatedStorage")
local maps = replicatedStorage:WaitForChild("Maps")
function teleportAllPlayers()
local target = CFrame.new(workspace.TeleportTarget.Position)
for i, player in ipairs(game.Players:GetChildren()) do
player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
player.Playing.Value = 1
end
end
function pickGame()
local mapList = maps:GetChildren()
local selectedIndex = math.random(1,#maps)
local map = mapList[selectedIndex]:Clone()
map.Parent = game.Workspace
map.Name = "CurrentMap"
for i, player in ipairs(game.Players:GetChildren()) do
player.PlayerGui.GameStuff.TopText.TextLabel.Text = "Minigame chosen! Teleporting players..."
player.PlayerGui.GameStuff.ChosenGame.ImageLabel.Chosen.Text = workspace.CurrentMap.MapName.Value
player.PlayerGui.GameStuff.ChosenGame:TweenPosition(UDim2.new(0.51, -250,0.5, -150), "Out", "Back", 3)
wait(5)
player.PlayerGui.GameStuff.ChosenGame:TweenPosition(UDim2.new(-1, -250,0.5, -150), "In", "Back", 3)
end
teleportAllPlayers()
end
function doMinigameStuff()
end
function unloadMap()
if workspace:FindFirstChild("CurrentMap") then
workspace.Map:Destroy()
end
for i, player in ipairs(game.Players:GetChildren()) do
if player.Playing.Value == 1 then
player.Character.Humanoid.Health = 0
end
end
end
function playersCurrentlyPlaying()
for i, player in ipairs(game.Players:GetChildren()) do
if player.Playing.Value == 1 then return true end
end
end
game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
player.Playing.Value = 0
end)
end)
local playing = Instance.new("IntValue", player)
playing.Value = 0
playing.Name = "Playing"
end)
while(true) do
wait(10)
if #game.Players:getPlayers() >= minPlayers then
if playersCurrentlyPlaying() then
for i, player in ipairs(game.Players:GetChildren()) do
player.PlayerGui.GameStuff.TopText.TextLabel.Text = "Waiting for current game to end..."
end
else
for i, player in ipairs(game.Players:GetChildren()) do
player.PlayerGui.GameStuff.TopText.TextLabel.Text = "Picking minigame..."
end
wait(4)
pickGame()
end
else for i, player in ipairs(game.Players:GetChildren()) do player.PlayerGui.GameStuff.TopText.TextLabel.Text = "Need 2 or more players!" end end
end
I should probably add that a lot of this is from the Wiki, I'm not too great at scripting.
It outputs the following:
Workspace.MainGame:15: attempt to get length of upvalue 'maps' (a userdata value)

3 comments
Can you post the whole script please? I think something is wrong with one of your variables.
Please post the whole script like CStarLam said or we can't help you.
I've edited the post with the whole script.