Table of Strings Returns as "false"

  1. What do you want to achieve? I’m working on what is essentially a crafting system. A modulescript contains the materials required to upgrade a given weapon, from levels 1-10.

  2. What is the issue? When printed, my table is returning levels 1-10, but instead of showing as strings listing the material’s name, they all show up as “false.”
    ExampleOfError

  3. What solutions have you tried so far? I looked at other posts on the DevForum but none seemed to have this exact issue.

This is the code I have in the ModuleScript, which is in ReplicatedStorage:

local module = {}

local KeybladeMaterials = {
	--Example--
--	[1] = {Soothing Stone = 2, Sinister Stone = 1, Orichalcum = 1} --

	[1] = {"Lucid Shard" == 1},
	[2] = {"Lucid Shard" == 2},
	[3] = {"Hungry Shard" == 2},
	[4] = {"Lucid Shard"==3,"Hungry Shard"==2,},
	[5] = {"Blazing Shard"==3},
	[6] = {"Lucid Shard"==3,"Hungry Shard"==3,"Blazing Shard"==3},
	[7] = {"Lucid Stone"==1},
	[8] = {"Lucid Stone"==3},
	[9] = {"Blazing Stone"==1},
	[10] = {"Mythril Shard"==1},
}

module.ReturnedInformation = function(plr, keybladeLevel)
	print('Returned information for: ' .. script.Name)
	print(plr)
	print(keybladeLevel)
	print(KeybladeMaterials) --All values return as [1]=false

	return KeybladeMaterials[keybladeLevel]
end

return module

And this is the code I have on the client, which is caling require() on it.

local KeybladeInfo = require(ReplicatedStorage.Modules.KeybladeInfo)
local CurrentMaterials = KeybladeInfo.ReturnedInformation(Player, 2) --The "2" is a stand-in for the weapon's level.
				
print(CurrentMaterials)--This returns as [1] = false

Any help would be appreciated!

== is the operator that converts things into true/false.
In this case, you’re asking if “Lucid Shard” is the same thing as 3, and since it’s not, it will evaluate to false.
When you assign keys in a table, you need to use brackets.

[6] = { ["Lucid Shard"] = 3, ["Hungry Shard"] = 3 }
1 Like

You know why we use ==s in if statements? Just because of that. == will return if its equal or not. thats why it returned all false, consider turning it to a dictionary.

1 Like

Thank you! I was really hoping it was something as simple as this. I will try it out and let you know if something else goes wrong!

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