I just plonked it in, not really knowing what needs to be changed, removed, but heres what I got
local data = {
Classes = {
['Knight'] = {
['ID'] = 1,
['Owned'] = true,
['Weapons'] = {
'Classic Sword',
},
['Armours'] = {
'Knight Armour'
},
['Trails'] = {
'None'
},
},
['Archer'] = {
['ID'] = 2,
['Owned'] = true,
['Weapons'] = {
'Bow and Arrow'
},
['Armours'] = {
'Archer Armour'
},
['Trails'] = {
'None'
},
},
['Scout'] = {
['ID'] = 3,
['Owned'] = false,
['Weapons'] = {
'Dagger'
},
['Armours'] = {
'Scout Armour'
},
['Trails'] = {
'None'
},
},
},
ClassEquips = {
EquippedKnight = {
Weapon = 'Classic Sword',
Armour = 'Knight Armour',
Trail = 'None'
},
EquippedArcher = {
Weapon = 'Bow and Arrow',
Armour = 'Archer Armour',
Trail = 'None'
},
EquippedScout = {
Weapon = 'Dagger',
Armour = 'Scout Armour',
Trail = 'None'
},
},
EquippedClass = 'Knight',
Level = 1,
Exp = 0,
Gold = 100,
Gems = 0,
}
local httpService = game:GetService("HttpService")
local playerDataStore = game:GetService("DataStoreService"):GetDataStore("test005")
local playersData = {}
function updateObject(old, new)
local update = {}
for name, variable in next, new do
update[name] = (type(variable) == 'table' and old[name] and updateObject(old[name], variable)) or old[name] or variable
end
return update
end
game.Players.PlayerAdded:Connect(function(player)
playersData[player.UserId] = {}
local function addressTable(receivedValue)
local function produceTable(fromValue)
local tableToReturn = {}
for key, value in pairs(receivedValue) do -- yes
tableToReturn[key] = addressTable(value)
end
return tableToReturn
end
return type(receivedValue) == "table" and produceTable(receivedValue) or receivedValue
end
for k, v in pairs(data) do -- assuming "data" is your prefab, changed that part for you
playersData[player.UserId][k] = addressTable(v) -- yes
end
local loadJSON = playerDataStore:GetAsync(player.UserId)
local setData = (loadJSON and httpService:JSONDecode(loadJSON)) or nil
-- Data part
if setData then
for key, value in pairs(setData) do
if playersData[player.UserId][key] then
playersData[player.UserId][key] = addressTable(value)
end
end
end
updateObject(playersData[player.UserId], data)
local user = playersData[player.UserId]
print(user.Classes.Scout)
end)
game.Players.PlayerRemoving:Connect(function (player)
local saveJSON = httpService:JSONEncode(playersData[player.UserId])
playerDataStore:SetAsync(player.UserId, saveJSON)
end)
Didnt actually seem to change anything, probs cause I did it completely wrong