I want to be able to search into a dictionary for a value.
The dictionary was also stored in a datastore where i do successfully reach and i can access that value I am searching for in the datastore but not when I am looking in the server dictionary for the value.
The error read attempt to index nil with Fishing
~~ this is the dictionary code to start the stored values
playerStats = {
Craft = {
Cooking = {
Lvl = 1,
Exp = 0
}
},
Resource = {
Fishing = {
Lvl = 1,
Exp = 0
}
}
}
~~ storing the dictionary, storedata used to permantly store the data while the _G.dictionary used to temporary store data to be used in game by server
local function onAddPlayer(Player)
local player = Player.UserId
local getStats = PlayerStats:GetAsync(player) or 0
if getStats and getStats ~= 0 then
local updateStats = PlayerStats:GetAsync(player)
_G.PlayerStat[player] = updateStats
elseif getStats == 0 then
local updateStats = PlayerStats:SetAsync(player, playerStats)
_G.PlayerStat[player] = updateStats
end
end
Player.PlayerAdded:Connect(onAddPlayer)
~~ attempting to use dictionaries both datatstore and global
function ActTask.onActTask(Player, Category, Skill, Task, RLvl, TTime, Exp, LExp)
local plyrStat = PlayerStats:GetAsync(Player.UserId)
local pTLvl = plyrStat[Category][Skill]["Lvl"]
local runTime = 0
local aTime = 0
local sPSExp = plyrStat[Category][Skill]["Exp"] ~~ proof of working dictionary search below
print("sPSExp " .. sPSExp) ~~ returns exp value of 0 correct answer
print("category " .. Category) returns proper category "Resource"
print("skill " .. Skill) ~~ returns proper Skill "Fishing"
print(_G.PlayerStat[Player.UserId]) ~~ returns data
_G.PlayerStat[Player.UserId][Category][Skill]["Exp"] = sPSExp ~~ this is the code returning the error
end