Does anyone know how to make a proximity prompt for daily rewards? Like you go up and claim your daily income, and every day it goes up a certain amount.
Datastore for last collected value and a value which stores the last time player joined.
For clarification, do something like this;
Time Value in seconds -1 for every second the player is ingame, make sure this resets at the beginning of the day. When player rejoins, subtract earlier time from current time to get time left until opening.
Daily income increase I reccomend something like this;
Set Amount * Day
Take a look at this post first:
Then after that, there are ways to connect this to a proximity prompt, meaning you change the time the player joined to the time of when the proximity prompt was activated.
So instead of doing game.Players.PlayerAdded:Connect(function(player)
with the datastore, you would replace that function with a proximity prompt function, like so:
local DataStoreService = game:GetService("DataStoreService")
local DailyRewardDataStore = DataStoreService:GetDataStore("DailyReward")
local ProximityPrompt = game.Workspace:WaitForChild("ProximityPrompt")
ProximityPrompt.Triggered:Connect(function(player)
pcall(function()
local foundData = DailyRewardDataStore:GetAsync(player.UserId)
if foundData then
if tonumber(foundData) < os.time() - 86400 then
print(player.Name.." is receiving their daily reward")
--Add to the player's leaderstats here
DailyRewardDataStore:SetAsync(player.UserId,os.time())
else
print("Come back later!")
end
else
DailyRewardDataStore:SetAsync(player.UserId,os.time())
end
end)
end)