Sup
I have a TextButton, leaderstats and their DataStore system.
Leaderstats have one child: Money
If I’ll click the TextButton the value of Money will decrease by 1
The value is decreasing but if i’m leaving the game the Money isn’t saving
The DataStore system isn’t working or the TextButton?
TextButton Script:
repeat wait() until game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
plr.PlayerGui.ScreenGui.decrease.MouseButton1Click:Connect(function()
local money = plr.leaderstats.Money
money.Value = money.Value-1
print("Value:".. money.Value)
end)
Location of TextButton: game.StarterGui.ScreenGui.decrease
The TextButton script is inside the TextButton
DataStore/leaderstats system script:
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 = "key-".. 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 = “key-”… plr.UserId
DS:SetAsync(key,plr.leaderstats.Money.Value)
end)
The DataStore/leaderstats system script is inside ServerScriptService
What i’m doing wrong? It’s the TextButton not working or DataStore?
(What i want: When i click the TextButton the value of Money will decrease by 1 and when I’ll this value will save)
Please help me.