I have been trying to make a map randomiser for the past 2 hours and i am having trouble it says "attempt to index number with 'Map'" on line 3 i have tried math.random(1, #Maps), random.new(1, #Maps) and neither have worked please help as i cant continue making a game without this working.
EDIT: I changed the code a little still dosent work NEW ERROR: ServerScriptService.MapChooser.Selector:14: attempt to index number with 'Sky'
local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren() local Map = math.random(1, #Maps) local MapClone = Maps[Map]:Clone() local Intermission = game.ReplicatedStorage:WaitForChild("MapStuff"):WaitForChild("Intermission") while wait() do print("Intermission.") if Intermission.Value == true then wait() elseif Intermission.Value == false then print("No Longer Intermission.") MapClone.Map.Parent = workspace print("Cloned To Workspace.") Map.Sky.Parent = game.Lighting print("Lighting.") end end
Try this
local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren() local Map = math.random(1, #Maps) local MapClone = Maps[Map]:Clone() local Intermission = game.ReplicatedStorage:WaitForChild("MapStuff"):WaitForChild("Intermission") while wait() do print("Intermission.") if Intermission.Value == true then wait() elseif Intermission.Value == false then print("No Longer Intermission.") MapClone.Map.Parent = workspace print("Cloned To Workspace.") MapClone.Sky.Parent = game.Lighting print("Lighting.") end end
The Map.Sky.Parent = game.Lighting
is probably wrong. Maybe you should change it to Map.Sky.Parent = game:GetService("Lighting")
.