I’ve just started messing around with datastore 2 and made my first data set but for some reason it doesn’t save the values I change in game. Any ideas or clues as to what I did wrong?
local dataStore2 = require(1936396537)
local mainKey = "MainKey"
dataStore2.Combine(mainKey, "Stats")
--Data Table
local function SetDataTable()
local UserData = {
Stats = {
["Level"] = 1,
["Health"] = 23,
["Strength"] = 1.4,
["CurrentFloor"] = 2960738307,
["PlaceName"] = "N/A",
["Mana"] = 20,
["MaxMana"] = 20,
["Lyrics"] = 100,
["LegacyGems"] = 0
}
}
return UserData
end
--Main
game.Players.PlayerAdded:Connect(function(plr)
local UserData = dataStore2(mainKey,plr):Get(SetDataTable())
--PLAYER STATS--
local stats = Instance.new("Folder")
stats.Name = "Stats"
local lvl = Instance.new("IntValue")
lvl.Name = "Level"
local hp = Instance.new("IntValue")
hp.Name = "Health"
local str = Instance.new("NumberValue")
str.Name = "Strength"
local cF = Instance.new("IntValue")
cF.Name = "CurrentFloor"
local pN = Instance.new("StringValue")
pN.Name = "PlaceName"
local mana = Instance.new("DoubleConstrainedValue")
mana.Name = "Mana"
local lyrics = Instance.new("IntValue")
lyrics.Name = "Lyrics"
local lGems = Instance.new("IntValue")
lGems.Name = "LegacyGems"
local StatsData = dataStore2("Stats", plr)
local function UpdateStats(UpdatedValue)
lvl.Value = StatsData:Get(UpdatedValue).Level
hp.Value = StatsData:Get(UpdatedValue).Health
str.Value = StatsData:Get(UpdatedValue).Strength
cF.Value = StatsData:Get(UpdatedValue).CurrentFloor
pN.Value = StatsData:Get(UpdatedValue).PlaceName
mana.MaxValue = StatsData:Get(UpdatedValue).Mana
lGems.Value = StatsData:Get(UpdatedValue).LegacyGems
end
UpdateStats(UserData.Stats)
StatsData:OnUpdate(UpdateStats)
stats.Parent = plr
lvl.Parent = stats
hp.Parent = stats
str.Parent = stats
cF.Parent = stats
pN.Parent = stats
mana.Parent = stats
lGems.Parent = stats
print("Successfully loaded")
end)