I'm trying to make it so when a stat changes, it saves. It isn't s stupid leaderstat. It's a IntValue inside a Gui. This is what I have so far; it doesn't work at all. I'm new to datastore and personally think it's stupid. I was just trying to save the ki value but still added the stamina and attack for later.
There are no errors. The problem is that the Ki value won't save
--Btw this is a script in Workspace
local DataStore = game:GetService("DataStoreService"):GetDataStore('SSJClickerSaves')
game.Players.PlayerAdded:connect(function(Player)
local PlayerId = 'id-'.. Player.userId
local Ki = Player.PlayerGui.Stats.StatsFrame.Ki:FindFirstChild("KiVal")
local Attack = Player.PlayerGui.Stats.StatsFrame.Physical:FindFirstChild("AttackVal")
local Stamina = Player.PlayerGui.Stats.StatsFrame.Stamina:FindFirstChild("StamVal")
local Save = DataStore:GetAsync(PlayerId)
if Save then
Ki.Value = Save[1]
local SaveValues = {Ki.Value}
DataStore:SetAsync(PlayerId, SaveValues)
end
end)
game.Players.PlayerRemoving:connect(function(Player)
local PlayerId = 'id-'.. Player.userId
local SaveTable = {Player.PlayerGui.Stats.StatsFrame.Ki.KiVal.Value}
DataStore:SetAsync(PlayerId, SaveTable)
end)
This is for a DBZ game I'm making. It's in the pre-est of pre alphas.

3 comments
Although your script didn't quite work, I appreciate all the effort. Also, this gave me a better idea of how the dataStore works <3
no problem, good luck!
I would not use a changed event to save player stats, this will exceed the limitations.