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

How do I fix a userdata value bug?

Asked by
Spoookd 32
8 years ago

I got some code from the "Map Chooser" wiki page from roblox. On a part of the script, it chooses a map. It picks from a folder called maps which is located in the ReplicatedStorage.

This is the line of code it is in (inside a function called "pickMap"):

local selectedIndex = math.random(1, #maps)
local map = mapList[selectedIndex]:Clone()

"maps" is a variable outside the function:

local maps = replicatedStorage:WaitForChild("Maps")

This is the error I get: ServerScriptService.Script:9: attempt to get length of upvalue 'maps' (a userdata value)

If you want the whole page of code, search "Map Chooser" on the roblox wiki.

2 answers

Log in to vote
1
Answered by
shayner32 478 Trusted Moderation Voter
8 years ago

You can't get the length of an Instance. You can however, get the number of children of said Instance, which you are meaning to do.

local selectedIndex = math.random(1, #maps:GetChildren())
local map = mapList[selectedIndex]:Clone()
Ad
Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

maps is a ROBLOX Object, probably a Model. You need to use GetChildren on it to get a Table:

local maps = replicatedStorage:WaitForChild("Maps"):GetChildren()

Answer this question