I am trying to choose maps from the ReplicatedStorage and set the value of a StringValue to the name of the map:
local players = game.Players:GetChildren() local maps = game.ReplicatedStorage.Maps:GetChildren() local currentmap = game.Workspace:WaitForChild("CurrentMap") local chosen = script.ChosenMap local spawner = game.Workspace.Spawn -- Change name local choices = {maps} function choose() for i = 1,#maps do if maps[i]:IsA("Model") then maps[i] = #choices + 1 -- I was told to use '#choices + 1 = maps[i]' but it can't go like that. end end local picked = math.random(1, #choices) print(choices[picked]) chosen.Value = choices[picked].Name wait() end
Some of this code was changed a bit from someone in my last post.
But it just prints table: 33931ACC
and an error pops up every time and I can't figure out why:
Workspace.CurrentMap.Script:25: bad argument #3 to 'Value' (string expected, got nil)
This is because on line 6, you put the GetChildren() table inside of a table. You basically put a table inside of a table. Remove the {} around maps, and it should work.
Do picked = math.random(#maps) and remove the whole function since you don't even call it unless I'm looking at it wrong.
Also for future reference, you can call workspace by doing just workspace instead of game.Workspace