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

Attempted to index nil with DName??

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

2 comments

0

Any moderators on this question, sorry, this was meant for another question.

0

Not really...

1 answer

✓ Accepted answer

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

1 comment

0

Im accepting this because he helped me in the chat :3

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