Hi, so lately I’ve been working on a new type of DataStore in which I want the DataStore to be able to save extra data such as data stored in tools. So basically, Player > Tools > Tool Data. The tools are saved, but the data stored inside the tool is not.
Here’s the simple idea that I want:
function checkingplayerinfo(player)
local data = datastore:GetAsync(player.UserId)
if data then
newdata[player.UserId] = data
print("Loading Player's Saved Data!")
else
data = {
Tools = {[SampleSword1] = {Upgrade = 0,
MaxUpgrade = 0,
Stars = 0}, --//Closes the SampleSword1 Table
[SampleSword2] = {Upgrade = 0,
MaxUpgrade = 0,
Stars = 0} --//Closes the SampleSword2 Table
}, --//Closes the ToolTable
OtherData = {} --//Closes OtherData
} --//Closes the Data Table
newdata[player.UserId] = data
print("Giving New Data to New Player!")
end
return data
end
Here’s what I have:
function checkingplayerinfo(player)
local data = datastore:GetAsync(player.UserId)
if data then
newdata[player.UserId] = data
print("Loading Player's Saved Data!")
else
data = {
Tools = {},
OtherData = {} --//Closes OtherData
}
newdata[player.UserId] = data
print("Giving New Data to New Player!")
end
return data
end
--// Calls Data from previous Session
function getplayerdata(player)
local data = newdata[player.UserId]
if data then
print("Data Received")
return data
else
print("An Error occurred when Getting Data!")
end
return false
end
--//Convert Saved Data to Game's DataStore
function setplayerdata(player, data)
if not data then
return false
end
datastore:SetAsync(player.UserId, data)
return true
end
--// Saves Data
game.Players.PlayerRemoving:Connect(function(player)
local settingdata = getplayerdata(player)
if settingdata then
for i , v in pairs(settingdata.Tools)do
table.remove(settingdata.Tools, i) --// Prevents Tool Duplication
end
---------------------- [THIS IS WHERE I'M HAVING TROUBLE!!!] ----------------------
for i, v in pairs (player:WaitForChild("StarterGear"):GetChildren())do
local upgrade = v.Upgrade --// an intvalue stored inside the Weapon
local maxupgrade = v.MaxUpgrade --// an intvalue stored inside the Weapon
local stars = v.Stars --// an intvalue stored inside the Weapon
------------------------------------------// I assume this makes the table I want?------------------------------------------
table.insert(settingdata.Tools, {[v.Name] = {'Upgrade', 'MaxUpgrade', 'Stars'}})
settingdata.Tools[v.Name].Upgrade = upgrade.Value
-----------------------------------------attempt to index field '?' (a nil value)-------------------------------------------
settingdata.Tools[v.Name].MaxUpgrade = maxupgrade.Value
settingdata.Tools[v.Name].Stars = stars.Value
print(settingdata.Tools[v.Name].Upgrade) --// Doesn't Work.
print("ToolDataSaved")
end
setplayerdata(player, settingdata)
newdata[player.UserId] = nil
else
print("Error when saving data!")
end
end)
I really don’t understand how to make a table in another table and grab that custom-named table. That’s my main problem. Any kind of help would be appreciated. Thanks for reading my post!