How can I get data from the data store and store it in a table in the game so that I can query the data from the table later?
The problem is that I must use LoadData() before CheckData(), is there a way to just use CheckData() without using LoadData()?
local PlayersData = {} function LoadData(Player,Slot) PlayersData[Player.Name] = { ["Something"] = false } print(PlayersData) -- this shows playername and "Something" inside end function CheckData(Player,Slot,...) local path = {...} print(PlayersData) -- this shows nothing in table end
I need to call the LoadData() function once (when player joins the game) to save the data in the game until the player leaves, so that every time I use CheckData() it will give me the latest saved data.
You can use a conditional statement to check if the player index exists in the PlayerData:
function CheckData(Player,Slot,...) local path = {...} if PlayersData[Player.Name] then print("Data found") --Add code that handles data if there is data loaded else print("No Data found") --Add code that handles data if there is none loaded print(PlayersData) -- this shows nothing in table end
Edit: Apologies for poor format, the tab button wasn’t working for while I was writing the post