[SOLVED]How Would you Print This?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Print Attributes (Wood for example)

  2. What is the issue? Include screenshots / videos if possible!
    I dont know how

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    everything I could think of

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

{Name = "False Heavenly Root", Description = "You have False Heavenly Root", Attributes = {Fire = "Fire", Wood = "Wood", Earth = "Earth", Water = "Water", Metal = "Metal"}

print(table_name.Attributes.Wood)

Can we see more of the script? eirhbdislgbebgiufse

you can try:

print(nameoftable.Attributes.Wood)

sure,

function RandomRootGiver()
	local profile = dataManager.Profiles[player]
	local falseHeavenlyRoot = profile.Data.Roots[1]
	
	print("Name:", falseHeavenlyRoot.Name)
	print("Description:", falseHeavenlyRoot.Description)
	print("Attributes:")
	print("Qi Gain:", falseHeavenlyRoot.QiGain)
	print("Chance:", falseHeavenlyRoot.Chance)

	for _, attribute in falseHeavenlyRoot do
		print(attribute.Wood)
	end
end	

When I try this it print

attemp to index nil with wood

The reason it is throwing that error is probably because the “attribute” variable in the for loop does not equal anything, meaning that the for loop did not return anything when going through the table. Remember: you must use pairs() when using a for loop like that, as you need the iterator function for the for loop to work. It seems like you forgot to use the pairs() function, so you can just replace that.

Basically: use pairs()

function RandomRootGiver()
	local profile = dataManager.Profiles[player]
	local falseHeavenlyRoot = profile.Data.Roots[1]
	
	print("Name:", falseHeavenlyRoot.Name)
	print("Description:", falseHeavenlyRoot.Description)
	print("Attributes:")
	print("Qi Gain:", falseHeavenlyRoot.QiGain)
	print("Chance:", falseHeavenlyRoot.Chance)

	for _, attribute in pairs(falseHeavenlyRoot) do
		print(attribute.Wood)
	end
end

Actually, I think there’s also another thing wrong with the script
It seems like you’re only trying to print one attribute, which you don’t need a for loop for
Also, you were trying to loop through the entire falseHeavenlyRoot for the attributes instead of the attribute table inside the falseHeavenlyRoot

Thank you, but no need for that,

problem was this line of code

local falseHeavenlyRoot = profile.Data.Roots[1]

I just removed

[1]

And now It works

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.