Hey there so I am trying to save a value called SpeedEnabled using DataStore2 but the problem is that when I update the data it changes and even changes on the Gui but when I leave and rejoin the game the Data resets. I am saving a lot of other values using DataStore2 and all of them are saving and loading correctly but this value saves but resets when I rejoin the game. Help would be appreciated!
Saving:
local DataStore2Module = game:GetService("ServerScriptService"):WaitForChild("DataStore2")
local DataStore2 = require(DataStore2Module)
local DefaultSpeedStatsSpeedAmountValue = 32
local DefaultSpeedStatsEnabledValue = false
local DataStoreCode = game.Workspace.DataStoreCode.Code
game.Players.PlayerAdded:Connect(function(Player)
--Speed
local SpeedStatsSpeedAmountDataStore = DataStore2("SpeedStatsSpeedAmount"..DataStoreCode.Value,Player)
local SpeedStatsSpeedAmount = Player:WaitForChild("SkillStats").SpeedStats.SpeedAmount
local function OnSpeedStatsSpeedAmountUpdated(UpdatedValue)
SpeedStatsSpeedAmount.Value = SpeedStatsSpeedAmountDataStore:Get(UpdatedValue)
end
OnSpeedStatsSpeedAmountUpdated(DefaultSpeedStatsSpeedAmountValue)
SpeedStatsSpeedAmountDataStore:OnUpdate(OnSpeedStatsSpeedAmountUpdated)
--Enabled
local SpeedStatsEnabledDataStore = DataStore2("SpeedStatsEnabled"..DataStoreCode.Value,Player)
local SpeedStatsEnabled = Player:WaitForChild("SkillStats").SpeedStats.SpeedEnabled
local function OnSpeedStatsEnabledUpdated(UpdatedValue)
print("Speed: "..tostring(SpeedStatsEnabledDataStore:Get(UpdatedValue)))
SpeedStatsEnabled.Value = SpeedStatsEnabledDataStore:Get(UpdatedValue)
end
OnSpeedStatsEnabledUpdated(DefaultSpeedStatsEnabledValue)
SpeedStatsEnabledDataStore:OnUpdate(OnSpeedStatsEnabledUpdated)
end)
Updating Value
local SpeedEnabledEvent = game:GetService("ReplicatedStorage"):WaitForChild("SkillEnabled").SpeedEnabled
local DataStoreCode = game.Workspace.DataStoreCode.Code
SpeedEnabledEvent.OnServerEvent:Connect(function(Player)
local DataStore2Module = game:GetService("ServerScriptService"):WaitForChild("DataStore2")
local DataStore2 = require(DataStore2Module)
local SpeedStatsEnabledDataStore = DataStore2("SpeedStatsEnabled"..DataStoreCode.Value,Player)
SpeedStatsEnabledDataStore:Set(true)
end)
It prints the true whenever the value updates which shows that the value saved but when I rejoin the game it prints false which is the default value and there are no errors in the output.