So I'm trying to make a daily reward system for a game, and if the player gets any points any other way than the daily reward system, then those points don't save, only points from the daily reward.
local vipGamepassID
local marketPlaceService = game:GetService("MarketplaceService")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("DailyReward")
local dailyRewardWait = .002 -- hours put /3600 for seconds
local reward = {350, 1500} -- points
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = 'leaderstats'
local points = Instance.new("NumberValue")
points.Value = 0
points.Parent = player.leaderstats
points.Name = 'Points'
local userData
pcall(function()
userData = dataStore:GetAsync(player.UserId..'1')
end)
if userData then
if (os.time() - userData.rewardWait) / 3600 >= dailyRewardWait then
if player.Name == "ChillTart" then
game.ServerStorage.VipDailyReward:Clone().Parent = player.PlayerGui
userData = {points = userData.points + reward[2]; rewardWait = os.time();}
else
game.ServerStorage.DefaultDailyReward:Clone().Parent = player.PlayerGui
userData = {points = userData.points + reward[1]; rewardWait = os.time();}
end
dataStore:SetAsync(player.UserId..'l', userData)
end
points.Value = userData.points
else
game.ServerStorage.NewPlayerNotification:Clone().Parent = player.PlayerGui
dataStore:SetAsync(player.UserId..'l', {
points = 0;
rewardWait = os.time();
})
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local saved, failed = pcall(function()
dataStore:SetAsync(player.UserId..'l', player.leaderstats.Points.Value)
end)
if saved then
print'saved'
else
print'datastore failed'
print(failed)
end
end)
