Still have questions? Join our Discord server and get real time help.
0

# Error that says user data value. Trying to do a script??

Edited 2 years ago

Hi, I'm trying to make a game. I will not say anything about the game besides what I need to help for. Because I don't want to leak the game.

It's a status thing, when the intermission is done it spawns chests, and then other better chests. I am using a usage of Module script etc.

The problem is not the module script but when it tries to spawn the chests. Error: "17:19:52.930 - ServerScriptService.Handler:25: attempt to get length of local 'normal' (a userdata value)"

This is the script:

local m = require(game.ServerStorage.RoundAPI) -- requires the module script.
local chests = game.ReplicatedStorage.Chests -- locates the chests folder i nthe replicated storage
local legendary = chests.Legendary -- where the legendary chests are
local rare = chests.Rare -- where the rare chests are
local normal = chests.Normal -- where the normal chests are

while wait() do
for i = 15,0,-1 do
wait(1)
end
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character then
player.Character:MoveTo(workspace.PlayingSpawn.Position)
end
end
wait(1)
wait(1)
wait(.3)
wait(.7)
for y = 5,#normal do -- It spawns 5 chests. One chest every 3 seconds.
local newNormal = normal[y]:Clone() -- clones the chest
newNormal.Parent = workspace.CurrentChests.Normal -- put the chest in the folder in workspace
wait(3) -- wait 3 seconds, and then repeats this 5 times.
end -- ends the
wait(10)
wait(.7)
for z = 5,#normal do
local newNormal = normal[z]:Clone()
newNormal.Parent = workspace.CurrentChests.Normal
wait(3)
end
wait(15)
wait(math.random(.7,1.7))
for g = 3,#rare do
local newRare = rare[g]:Clone()
newRare.Parent = workspace.CurrentChests.Rare
wait(5)
end
wait(25)
wait(3)
m.updateStatus("You have 10 seconds on you before the chests clears!")
wait(math.random(.7,1.7))
for h = 4,#legendary do
local newLegendary = legendary[h]:Clone()
newLegendary.Parent = workspace.CurrentChests.Legendary
wait()
end
for l = 10,0,-1 do
wait(10)
end
workspace.CurrentChests.Legendary:ClearAllChildren()
workspace.CurrentChests.Rare:ClearAllChildren()
workspace.CurrentChests.Normal:ClearAllChildren()
wait(.6)
for d = 3,0,-1 do
wait(.1)
end
end


There is more to the script but it's not neccessary.

0
You might want to do for y = 1, chests.Normal:GetChildren() also. hiimgoodpack 2009 — 2y

The '#' is called the length operator, which returns the length of an array (or a string). You're trying to get the length of an Instance (type is userdata). I think you mean to use chests.Normal:GetChildren()