Ok, so my first issue is the Data Store not updating when a Variable changes. The current code I have for this is
var1.Changed:Connect(function()
print("Saving. . .")
data1:SetAsync(player.UserId, var1.Value)
print(player.Name.. "'s data of "..var1.Value.." "..var1.Name.." has been saved!")
end)
To me, it seemed like it wasn't recognising that the Value had changed because it never printed 'Saving...' but I can't understand why...
Second of all the data never saves when the player leaves the game.
game.Players.PlayerRemoving:Connect(function(player)
print("Saving. . .")
data1:SetAsync(player.UserId, player.leaderstats.Credits.Value)
print(player.Name.. "'s data of "..var1.Value.." "..var1.Name.." has been saved!")
end)
This prints out PureGamerGames's data of 0 Credits has been saved! however, I never set the Value to 0.
The only possible solution I thought maybe the issue was the game not recognising var1, however, I have it declared here.
local var1 = Instance.new("IntValue", stats)
var1.Name = "Credits"
var1.Value = data1:GetAsync(player.UserId, var1.Value) or 0
data1:SetAsync(player.UserId, var1.Value)
One thing to note is that I have API access enabled and I was testing this out in play test..

1 comment
Thank you, just modified it a little bit.