Hello all!
im play in lobby, got reward, give only 3 hours, rejoin game again got reward after closed game, what is save time no working :/ No know how to save the time left after closing, can fix? :3 - (when close game,to need time saved)
wait(10800) -- it 3 hours = 10800 seconds
currency = "Money" moneyboost = 25000 debounce = false function onTouch(hit) if hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == false then if game.Players:findFirstChild(hit.Parent.Name) ~= nil then local ThisPlayer = game.Players:findFirstChild(hit.Parent.Name) ThisPlayer.leaderstats:findFirstChild(currency).Value = ThisPlayer.leaderstats:findFirstChild(currency).Value + moneyboost if ThisPlayer.leaderstats:findFirstChild(currency).Value then game.Workspace.DailyReward.Parts.Gui.CustomPlayerTag.PlayerName.Text = "You were awarded!" end debounce = true wait(10800) game.Workspace.DailyReward.Parts.Gui.CustomPlayerTag.PlayerName.Text = "Daily Reward" debounce = false end end end script.Parent.Touched:connect(onTouch)
This utilizes DataStores. A Service that allows the developer to create or and or access a database tied to their game. Simultaneously using the tick()
function, we can use timestamps.
Pairing it with this Service to perform mathematical equations, we can detect the time passing.
local DataStoreService = game:GetService("DataStoreService") local DailyRewardTime = DataStoreService:GetDataStore("DailyReward") local PreviousTimeStamped local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(Player) local TimeRetrieve = pcall(function() PreviousTimeStamped = DailyRewardTime:GetAsync(Player.UserId) end) if (TimeRetrieve and PreviousTimeStamped) then if ((tick() - PreviousTimeStamped/3600) >= 24) then --// Add Coins DailyRewardTime:SetAsync(Player.UserId, tick()) --// Reset end end end) Players.PlayerRemoving:Connect(function(Player) DailyRewardTime:SetAsync(Player.UserId, tick()) end)
As the other answer mentioned, you do, indeed, need to make a DataStore.
A quick crash-course on how to create a DataStore:
local datastoreService = game:GetService("DataStoreService"); local datastore = datastoreService:GetDatastore("DataStoreName"); -- You can save stuff to whatever DataStore you need. --[[ You can save player's information to a Datastore VIA datastore:SetAsync(key, value); key is what you have saved (so like the player's UserID) and value is what you want to save to that, so think of it like a dictionary. You can get a player's saved data VIA datastore:GetAsync(key); -- retrieves all the information saved to 'key'. ]]--
If I didn't explain it well enough, here's some resources that I think you will benefit from.
[ What are DataStores? ] https://developer.roblox.com/en-us/articles/Data-store
[ Tutorial ] https://m.youtube.com/watch?v=DkYupSBUpes
You need to create a datastore, I'm not 100% sure on how to do this but you can look up a video on datastore.