I have been focusing time scripts in roblox and here is my new released Daily Reward system! You obviously change the script to change what you want to do if it is the day after, thanks!
local Players = game:GetService("Players")
local dataService = game:GetService("DataStoreService")
local timeData = dataService:GetDataStore("lastLogin")
local dayDifference = 1
Players.PlayerAdded:Connect(function(Player)
local timeKey = (Player.UserId..'-$loginTime')
local startingDate
local claimedToday = Instance.new("BoolValue")
claimedToday.Parent = Player
claimedToday.Name = "claimedToday"
local success, err = pcall(function()
startingDate = timeData:GetAsync(timeKey)
end)
if success then
if startingDate then
local startingString = string.split(startingDate,' ')
local todayDate = os.date()
local splitString = string.split(todayDate,' ')
if tonumber(splitString[3]) == tonumber(startingString[3] + dayDifference) and splitString[2] == startingString[2] and splitString[1] ~= startingString[1] then
print('Day after!')
claimedToday.Value = true
elseif splitString[1] == startingString[1] then
print('Same Day - '..os.date("%A"))
else
print(tonumber(splitString[3] - startingString[3]), 'days missed!')
end
else
print('No past date!')
end
else
print(err)
end
end)
Players.PlayerRemoving:Connect(function(Player)
if Player:WaitForChild("claimedToday").Value == true then
local timeKey = (Player.UserId..'-$loginTime')
local success, err = pcall(function()
timeData:SetAsync(timeKey,os.date())
end)
if success then
print(Player.Name..' left and data saved successfully!')
else
error(err)
end
end
end)
The way this works is that when the player leaves it saves the date they left and when they rejoin it gets the current date and compares the two to check if they join either the amount of days added in dayDifference after, the same day or over the dayDifference you added. The dayDifference is the amount of days you want the reward to fall under, 1 is daily, obviously. You can add your own daily benefits by editing where it says “print(‘Day after!’)”. This is the part that shows the day after, where it prints days missed it shows the amount of days since the player joined if it wasn’t the day after and for the Same Day, well… it explains itself! If there are any other issues feel free to reply to the forum or DM my Discord: aaronmansfield5#6864