[ game.StarterGui.ScreenGui ... TextButton ]
Hello Guys! I have a TextButton that's called "Upgrade", if I'll click this button the Money value (the leaderstats child) will decrease by the price over this TextButton
Illustration 1(one)
[ PRICE: 10$ ] --Price over the TextButton
[ UPGRADE ] --TextButton
[ MONEY: 631$ ] --Money(child of the leaderstats)
When I'll click this TextButton the money will decrease by the price over this TextButton
Illustration 2
[ PRICE: 15$ ] --Price over the TextButton
[ UPGRADE ] --TextButton
[ MONEY: 621$ ] --Money(child of the leaderstats)
BUT! When i'll leave the game the Money value from the Illustration 2 will not save... the Money value from the Illustration 1(one) will save, and now there's a big question... is this TextButton not changing the value of Money? or the DataStore isn't saving the changed value?
[ game.ServerScriptService.leaderstats ]
There's the code of the DataStore*(leaderstats)* system
local DS = game:GetService("DataStoreService"):GetDataStore("leaderstats")
game.Players.PlayerAdded:Connect(function (plr)
local stats = Instance.new("Folder",plr)
stats.Name = "leaderstats"
local money = Instance.new("IntValue",stats)
money.Name = "Money"
local key = "stats-".. plr.UserId
if DS:GetAsync(key) then
money.Value = DS:GetAsync(key)
else
DS:SetAsync(key,0)
money.Value = DS:GetAsync(key)
end
end)
game.Players.PlayerRemoving:Connect(function (plr)
local key = "stats-".. plr.UserId
DS:SetAsync(key,plr.leaderstats.Money.Value)
end)
As you guys can see, the code should work perfectly why it's not working? It's the DataStore system not working or the TextButton? Please help me! That's (i think) the biggest problem in my "game"
