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

Attempted to index nil with DName??

Asked by 4 years ago

So I have this UI script for my game that is like city smash. I keep getting this same error and I need help.

Code:

local Disasters = {
    Testing = {
        DName = "Testing Disaster",
        WhatItDoes = "This is just a test disaster. Nothing really.",
        Number = 1
    },
    Testing2 = {
        DName = "Testing Disaster 2",
        WhatItDoes = "This is just another test disaster.",
        Number = 2
    },
}

local AmountOfDisasters = 2

print("There are ".. AmountOfDisasters .." disasters in the game.")

function LoadSpots()
    local UI = script.Parent.DisasterGui
    local Item = UI.DisasterFrame

    if AmountOfDisasters == 1 then
        print("There is 1 disaster in game!")
    elseif AmountOfDisasters > 1 then
        for i = 1,AmountOfDisasters,1 do
            local Frame = Item:Clone()
            local Orgin = 0.5-(i/10)
            print(Orgin+((AmountOfDisasters+1)*0.05))
            Frame.Visible = true
            Frame.Parent = UI
            Frame.Position = UDim2.new(Orgin+((AmountOfDisasters+1)*0.05),0,0.9,0)
            print(Disasters[i].DName)
            Frame.Disaster.Text = Disasters[i].DName
            Frame.Number.Text = Disasters[i].Number
        end
        print(((AmountOfDisasters+1)*0.05))
    end
end
LoadSpots()
0
Any moderators on this question, sorry, this was meant for another question. JailBreaker_13 350 — 4y
0
Not really... SharkOwen_dev 69 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

You can't index a table with a set value.

0
Im accepting this because he helped me in the chat :3 SharkOwen_dev 69 — 4y
Ad

Answer this question