Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I keep getting the error: attempt to get length of a userdata value. How to fix this?

I'm trying to teleport the players from the lobby to a random map and display "The game is.. " and then the games name.

this is the script:

local status =  game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps

while true do
for i = 1,10 do
	status.Value = "Intermission.. "..10-i
	wait(1)
end

local rand = math.random(1, #maps)

local map = maps[rand]:Clone()
map.Parent = workspace

status.Value = "The game is.. "..map.name
wait(4)

this is the output:

ServerScriptService.Script:10: attempt to get length of a userdata value
Stack Begin
Script 'ServerScriptService.Script', Line 10
Stack End

1 answer

#Maps:GetChildren(), not maps. Maps is userdata value and it has a method called GetChildren that returns a table of all the children of it. Iterate over that.

3 comments

0

did u have to bolden it?

0

i didnt

0

oh, I understand what happened, hashtags signify a header in this editor but I meant to use it as length. should b fixed

This discussion is preserved as it was. New answers, comments, and votes are closed.