I have a system which puts data that isn’t for a specific player but has a special code that players use, it’s for a sharing thing I’m doing. But I want to make sure that the data expires after an amount of time so that way the data store isn’t filled with a bunch of unused data.
You can do this by waiting until the player disconnects and then make a live countdown in the background in disconnection, if the player joins back and the timer is still going the timer has not expired, else if the data gets removed, and if the player joins back make the timer reset and pause
I want it to expire even when the player is not in-game, besides the data does not hold anything about the player and only the thing that is being shared.
I won’t make it expire if Roblox can handle a bunch of data in one data store.
Do you still need this code after the server shuts down?
In both cases, you can start a new thread with a delay to delete the sepcified key after a certain amount of time:
task.delay(function()
Store:RemoveAsync() -- Or however you did it I forget
end)
If you do still need it, you can run periodic tasks in thr background which checks for stores that have expired and removes them. You may need an OrderedDataStore | Roblox Creator Documentation for this as I don’t believe you can loop through regular data stores.
If you don’t need the data after the server shuts down, you can hook the game shutdown event and delete all the codes at that time.
Roblox DataStores are essentially databases, they’re designed to store hundreds upon thousands of entries while still being fast to support the massive amount of games (experiences), players, and their data.
It is generally considered a good idea to remove data that you don’t need anymore though, so you should still use this.
game.Players.PlayerRemoving:Connect(function(player)
DataStore:RemoveAsync(user Id)
end)
Should work fine
I mean, my game really isn’t that popular and the share thing is something that not a lot of people would find out, so I will leave as it is.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.