Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 years ago
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
        m.updateStatus("Intermission: "..i.." Seconds!")
        wait(1)
    end
    for _, player in pairs(game.Players:GetPlayers()) do
        if player.Character then
            player.Character:MoveTo(workspace.PlayingSpawn.Position)
        end
    end
    m.updateStatus("Get Ready...")
    wait(1)
    m.updateStatus("Get Set...")
    wait(1)
    m.updateStatus("Go!")
    wait(.3)
    m.updateStatus("Normal Chests Spawning...")
    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)
    m.updateStatus("More normal chests spawning...")
    wait(.7)
    for z = 5,#normal do
        local newNormal = normal[z]:Clone()
        newNormal.Parent = workspace.CurrentChests.Normal
        wait(3)
    end
    wait(15)
    m.updateStatus("Rare chests spawning...")
    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)
    m.updateStatus("Legendary chests spawning...")
    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
        m.updateStatus("Chests Clear in: "..l.." Seconds!")
        wait(10)
    end
    workspace.CurrentChests.Legendary:ClearAllChildren()
    workspace.CurrentChests.Rare:ClearAllChildren()
    workspace.CurrentChests.Normal:ClearAllChildren()
    wait(.6)
    for d = 3,0,-1 do
        m.updateStatus("End in: "..d.." Seconds!")
        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

1 answer

Log in to vote
0
Answered by 2 years ago

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()

0
Thx, forgot about GetChildren() iiLevelMaker 111 — 2y
Ad

Answer this question