If I were to comment our the ["CaveDeaths"] = 0 part then it would error on the line above it. This is a script inside ServerScriptService. I can imagine this is an easy fix. Or does it have to relate to the datastore I’m using, DataStore2?
This is probably wrong but I believe you add commas at the end if there is something you’ll add below, try getting rid of the comma at the end of it, it would also explain why you would still get the error getting rid of the [“CaveDeaths”] = 0, part
Are you calling it on the DataStore2 table itself or on an instance of it? You should be doing the latter. Also you should be using combined data stores and saving a huge table defeats the purpose of combined data stores
I do use the combine function, but I’m not 100% sure what it does exactly. Correct me if I’m wrong, but does it combine all your data into one big table? Here is what I currently have:
local serverScriptService = game:GetService("ServerScriptService")
local serverStorage = game:GetService("ServerStorage")
local dataStore2 = require(serverScriptService.DataStore2)
local playerService = game:GetService("Players")
dataStore2.Combine("UserData","Coins","Gems","XP","Level","Trails","Achievements","Times")
playerService.PlayerAdded:Connect(function(player)
local coinData = dataStore2("Coins", player)
local gemData = dataStore2("Gems", player)
local levelData = dataStore2("Level", player)
local xpData = dataStore2("XP", player)
local achievements = dataStore2:GetTable({
-- here is just long lists of achievements
})
local times = dataStore2:GetTable({
-- another long list of times
});
local trails = dataStore2:GetTable({
-- long list of trails
});
-- rest is just modifying and saving data OnUpdate
so instead do I just get rid of the dataStore2:GetTable() part?
Also not sure what you mean by:
I looked up instance on the developer hub and It didn’t really make sense to me.
I’m not a super advanced scripter so could you just reword this.
The error you have means that the GetTable function is nil. This is the error one gets when one does
nil()
This means, in other words, that GetTable is not a function of dataStore2.
In OOP (Object-Oriented Programming) terms, the module DataStore2 is a class. You might have heard that term in the Roblox API Reference. For example, Part is a class. A class is a type. An instance is an individual.
If you’re calling GetTable() on the DataStore2 module itself (which, again, is a class), then it makes sense why it would not exist. GetTable() is only meant to be called on the DataStore2 instances, which can be created like this:
local statsStore = dataStore2("Statistics", player) -- All of the things in the table in your code could be stored as separate datastores and doesn't need to be stored as a single one
statsStore is an instance of dataStore2 and GetTable() can be called on it.