You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A tool spawner that lets u spawn a tool every 60 seconds, I have this, but I do not want to let people just server hop to escape the cooldown
What is the issue? Include screenshots / videos if possible!
I don’t know how to do this
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I cant find any
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
What you can do is when the player leaves the game it will save a time to their player. When the player joins back you can do math and calculate how long it has been since they left and joined.
Super simple, you will need to store the time at which they left and read it when they rejoin. This will obviously utilize a DataStore. In practice, the most utilized DataStore module is ProfileService, but assuming you’re just using the default, built-in DataStoreService: Your code may end up looking like this.
-- server
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local datastores = {}
Players.PlayerAdded:Connect(function(player)
local userData = DataStoreService:GetDataStore("UserData", player.UserId)
datastores[player.UserId] = userData
local timePlayerLeft = userData:GetAsync("timeLeft") or os.time()
local timePassed = os.time() - timePlayerLeft
-- do whatever with that
end)
Players.PlayerRemoving:Connect(function(player)
if not datastores[player.UserId] then
return
end
local timePlayerLeft = os.time()
datastores[player.UserId]:SetAsync("timeLeft", timePlayerLeft)
datastores[player.UserId] = nil
end)
Obviously, this is a very crude example of how your datastore code may end up looking. But the example is there.