Im trying to make a data store which stores the skills learned and their cost as the value, the skill is being saved and loaded properly, but not its value. For example, the skill name loads on the right place, but its value is set to 0, regardless of what it was before quitting the game.
edit: oops forgot a piece of the code
function save(player)
if player then
local unlockedskills = {}
local dataTree = game:GetService("DataStoreService"):GetDataStore("skilltree4")
for i, v in pairs(player:WaitForChild("unlockedskills"):GetChildren())do
unlockedskills[v.Name] = v.Value
end
dataTree:SetAsync(player.UserId, unlockedskills)
end
end
game.Players.PlayerAdded:Connect(function(plr)
local unlockedskills = Instance.new("Folder", plr)
unlockedskills.Name = "unlockedskills"
local success, errom = pcall(function()
local loadskills = dataTree:GetAsync(plr.UserId)
if loadskills then
print(loadskills)
for i,v in pairs(loadskills)do
local skill = Instance.new("IntValue", unlockedskills)
skill.Name = i
end
end
end)
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetChildren())do --NORMAL SAVE GAME CLOSE
save(v)
end
end)
--[[game:BindToClose(function()
if game:GetService("RunService"):IsStudio() then
for i, v in pairs(game.Players:GetChildren())do --STUDIO SAVE GAME CLOSE
save(v)
end
end
end)
]]
game.Players.PlayerRemoving:Connect(function(plr)
if game:GetService("RunService"):IsStudio() then --STUDIO SAVE PLAYER QUIT
save(plr)
end
end)
game.Players.PlayerRemoving:Connect(function(plr) --NORMAL SAVE PLAYER QUIT
save(plr)
end)