Error in the datastore! Attempt to call a table value!

data.AddedEvent = function(player)
	local Inventory = Instance.new("Folder", player); Inventory.Name = "Inventory"
	local playerGold = Instance.new("IntValue", Inventory); playerGold.Name = "Gold"
	
	--// Inventory System
    local playerArmour = Instance.new("StringValue", Inventory); playerArmour .Name = "Armour"
    local playerPotions = Instance.new("StringValue", Inventory); playerPotions .Name = "Potions"
	local playerWeapons = Instance.new("StringValue", Inventory); playerWeapons .Name = "Weapons"
	
	--// Player Stats
	local playerHealth = Instance.new("IntValue", Inventory); playerHealth.Name = "Health"
	local playerDamage = Instance.new("IntValue", Inventory); playerDamage.Name = "Damage"
	local playerMagicDmg = Instance.new("IntValue", Inventory); playerMagicDmg.Name = "MagicDamage"
	
	--// Datastore 
    local goldStore = Datastore2("Gold", player); local goldStoreData = goldStore:Get()
    local armourStore = Datastore2("Armour", player); local armourStoreData = armourStore({})
    local potionsStore = Datastore2("Potions", player); local potionsStoreData = potionsStore({})
	local weaponsStore= Datastore2("Weapons", player); local weaponsStoreData = weaponsStore({})
	local healthStore = Datastore2("Health", player); local healthStoreData = healthStore:Get()
	local damageStore = Datastore2("Damage", player); local damageStoreData = damageStore:Get()
	local magicStore = Datastore2("MagicDamage", player); local magicStoreData = magicStore:Get()
	
	--// JSON Encode/Decode
    playerArmour.Value = HttpService:JSONEncode(armourStoreData) -- Turning your items into a JSON table. we don't need to do this for gold as gold is a number and wont have multiple items inside
    armourStore:OnUpdate(function(decodedData)
         playerArmour.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
	end)

    playerPotions.Value = HttpService:JSONEncode(potionsStoreData) 
    potionsStore:OnUpdate(function(decodedData)
         playerPotions.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
	end)
    playerWeapons.Value = HttpService:JSONEncode(weaponsStoreData) 
    weaponsStore:OnUpdate(function(decodedData)
         playerWeapons.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
	end)
	
end

So this is my currenct datastore and for some reason when it gets to line 25 (which is the line under the datastore comment, about the armourstore) it says called a table value, and this is meant to be a table so I’m not sure, Also I’m new to scripting so sorry for the messy script.

Attempt to call basically means you are trying to use a table like a function

This error appears when a table contains both indexes (1,2,3,4, etc) and strings (“armor1”, “armor2”, etc) as keys. This is maybe the problem.

EDIT: Try to print all the keys in your table. This might be tricky and I am not 100% sure if ipairs will give you both so maybe try to iterate over the table with both pairs and ipairs and see if you have both numbers and strings as keys.

I don’t have anything in the table currently, since I haven’t made an armour, so the table should be empty right now. Unless that’s the problem.

One more thing. Where are you getting HTTPService from? I do not see it in the script.

This is wrong and irrelevant.

The issue is here; armourStore, potionsStore, and weaponsStore are tables, not functions. You meant to :Get({ }).

2 Likes

Thank you, I was wondering why there was an error. :heart:

I mean I said this first, but you showed a broader explanation

but you never showed OP where they made the mistake so

???

It is quite different. He actually gave a solution while you just reread the error text.

Nah I told him what the error meant