Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you fix a attempt to get length of upvalue 'maps' (a userdata value) error?

Asked by 8 years ago

This is my script;

01local replicatedStorage = game:GetService("ReplicatedStorage")
02local maps = replicatedStorage:WaitForChild("Maps")
03 
04function pickMap()
05    local mapList = maps:GetChildren() -- Declares a table of the maps inside of the Maps folder.
06    local selectedIndex = math.random(1,#maps) -- Choose a random number between 1, and the number of maps available.
07    local map = mapList[selectedIndex]:Clone() -- Create a clone of the map we selected.
08    map.Parent = workspace -- Parent it to the workspace.
09    map.Name = "Map" -- Rename the map so that we can use the unloadMap() function later to remove it.
10    return mapList[selectedIndex].Name -- Return the name of the map we selected, in case we want to display it.
11end
12 
13function unloadMap()
14    if workspace:FindFirstChild("Map") then -- If there is a model in the Workspace named "Map"
15        workspace.Map:Destroy() -- Destroy it!
View all 31 lines...

This is the entire output;

0122:32:56.305 - The Place I Learn To Script/Build was auto-saved to C:/Users/BlackOrange3343/Documents/ROBLOX/AutoSaves/Place_AutoSave_38.rbxl
02Ragdoll Physics Loaded
03Hello world!
0422:32:59.642 - Humanoid is not a valid member of Script
0522:32:59.644 - Stack Begin
0622:32:59.645 - Script 'Plugin_144773946.RealRagdoll.Ragdoll', Line 4
0722:32:59.646 - Stack End
08Loading Cutscene Editor...
09Bouyer's Ragdoll Physics Loaded
10Finished Loading.
11Loading Tree Gen...
12Finished Loading Tree Gen
1322:33:00.580 - Unable to load plugin icon. (x2)
14Realism Mod is running on v1.795!
15Cutscene Editor Loaded
View all 25 lines...

This is the error in the output;

122:33:03.719 - Workspace.MapChooser:6: attempt to get length of upvalue 'maps' (a userdata value)
222:33:03.721 - Stack Begin
322:33:03.723 - Script 'Workspace.MapChooser', Line 6 - global pickMap
422:33:03.724 - Script 'Workspace.MapChooser', Line 25
522:33:03.725 - Stack End

There are 2 lines with the error;

1local selectedIndex = math.random(1,#maps) -- Choose a random number between 1, and the number of maps available.

and

1local mapName = pickMap()

How can you fix this? Explain, thanks for any support, comments and answers!

0
thank you for asking this question it helped me. :o) chasedig1 115 — 6y

1 answer

Log in to vote
3
Answered by
dreamy67 135
8 years ago

The problem is your use of #maps. You are referencing the folder when you say maps. Instead, you want to say the number of objects inside the folder

try this instead:

1local selectedIndex = math.random(1,#mapList)
0
Thanks! This worked and helped me improve! BlackOrange3343 2676 — 8y
Ad

Answer this question