my leaderboard script doesnt save my minutes after i buy something, it reverts back to however many i had before i bought the item for however many minutes
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("TimeStats")
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Minutes"
Minutes.Parent = leaderstats
local UserID = "Player_".. player.UserId
local Data
local success, errormessage = pcall(function()
Data = DataStore:GetAsync(UserID)
end)
if success and Data then
Minutes.Value = Data.Minutes
end
coroutine.resume(coroutine.create(function()
while true do
wait(60)
Minutes.Value = Minutes.Value + 1
end
end))
end)
game.Players.PlayerRemoving:Connect(function(player) local UserID = "Player_".. player.UserId
local minutes = player.leaderstats.Minutes
local success, errormessage = pcall(function()
DataStore:SetAsync(UserID, minutes)
end)
if success then
print("Data Successfully Saved")
else
print("Could Not Save Data")
warn (errormessage)
end
end)
here is my buy script, its copy pasted and altered for other items but this is the basic template
local player = game.Players.LocalPlayer local croissant = game.ReplicatedStorage.Croissant local backpack = player.Backpack local remote = game.ReplicatedStorage.Buy
script.Parent.MouseButton1Click:Connect(function() if player.leaderstats.Minutes.Value >= 2 then player.leaderstats.Minutes.Value -= 2 croissant:Clone() croissant.Parent = backpack script.Disabled = true else script.Parent.Parent.Parent.Parent.Parent.ErrorMessage.Visible = true wait(2) script.Parent.Parent.Parent.Parent.Parent.ErrorMessage.Visible = false end
end)

2 comments
Could you show the script which handles buying?
Hey there, I received your message on Roblox!