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

[SOLVED] Stupid attempt to get length of field '?' (a nil value) error??

Asked by 6 years ago
Edited 6 years ago

So im trying to make a script where i have a function to find something in a table and it returns a object and i have this line of code:

print(items[stuff.Name])

but it errors with this: attempt to get length of field '?' (a nil value) but i have something that prints out "stuff" and it prints out fine.. items is a table.. If anyone has any idea why this is not working please help me its very annoying..

Heres the function code "Stuff"

The caller:

local stuff = getfromtable(items,game.ReplicatedStorage.SwordCrate:FindFirstChild(rewardbutton.ItemName.Text))

Function:

local function getfromtable(Table,Element)
    for i=1,#Table do
        local Value = Table[i]
        if Value.Name == Element.Name then
            return i
        end
    end
end

Here is the full code if you need it!

local CrateInude = false

local function opencrate(Chance)
    local result = nil
    if CrateInude == false then
        CrateInude = true
        local items = {}
local function FindTable(Table,Element)
    print(Element)
    if #Table == 0 then
        print("BOOOO")
        return false
    end
    for i=1,#Table do
        local Value = Table[i]
        print(Value.Name)
        if Value.Name == Element.Name then
            print("HOH YEA")
            return true
        else
            print("BOOOO")
        end
    end
    if Table[Element] then
    else
        return false
    end
end

local function getfromtable(Table,Element)
    for i=1,#Table do
        local Value = Table[i]
        if Value.Name == Element.Name then
            return i
        end
    end
end
        local frametimes = math.random(20,30)
        local rewardbutton
        script.Parent.Unboxing.inner:ClearAllChildren()
        for i,v in pairs(game.ReplicatedStorage.SwordCrate:GetChildren()) do
            local mathmatical = math.max(game.ReplicatedStorage.Raritys[v.Rarity.Value].Rarity.Value+Chance)
            for i = 1,mathmatical do
                --if game.Players.LocalPlayer.SwordStorage:FindFirstChild(v.Name) then
                --else
                    table.insert(items,v)
                --end
            end
        end

        math.randomseed(tick())    

        for i = 0,frametimes+5 do
            local item = items[math.random(#items)]
            local newsapme = script.Parent.Unboxing.SampleItem:Clone()
            newsapme.Visible = true
            newsapme.Parent = script.Parent.Unboxing.inner
            newsapme.ItemName.Text = item.Name
            newsapme.BackgroundColor3 = game.ReplicatedStorage.Raritys:FindFirstChild(item.Rarity.Value).Color.Value
            newsapme.ImageLabel.Image = "http://www.roblox.com/asset/?id="..item.ThumbnailId.Value
            newsapme.Position = UDim2.new(0,100*(i-1),0,0)
            if i == frametimes then
                rewardbutton = newsapme 
            end
        end
wait(5)
        for num = 1,(rewardbutton.Position.X.Offset - (255+math.random(-40,40)))/15 do
            for i,v in pairs(script.Parent.Unboxing.inner:GetChildren()) do
                v.Position = UDim2.new(0,v.Position.X.Offset -15,0,0)
                if v.Position.X.Offset <= -150 then
                    v:Destroy()
                end
            end
            script.Sound:Play()
            wait(0.01 * 1.05 ^ (num-105)/2)
        end
        if FindTable(items,game.ReplicatedStorage.SwordCrate:FindFirstChild(rewardbutton.ItemName.Text)) then
        local stuff = getfromtable(items,game.ReplicatedStorage.SwordCrate:FindFirstChild(rewardbutton.ItemName.Text))
        local result = #items[stuff]-1
        print(result.Name)
        for i=0,71 do
            wait()
            result.Rotation = result.Rotation + 5
        end
        end
        CrateInude = false
    end
end

opencrate(0)
0
This code does not seem to be a problem - can we see the full code? TheDeadlyPanther 2460 — 6y
0
We cant read your mind. What is "stuff"? What is "items"??????????? hiimgoodpack 2009 — 6y
0
items is a table.. did you read the question?? outlook1234567890 115 — 6y
0
you edited it i cant read the future if you cant tell............ hiimgoodpack 2009 — 6y
0
Also, wait() is deprecated, use Wait() hiimgoodpack 2009 — 6y

Answer this question