How do you tell if the server is new. New as in the server has not be played before as i want to run different codes for the first player. Thanks
It is possible to tell if server is new?
3 answers
You might want to check out this: https://developer.roblox.com/en-us/api-reference/property/Workspace/DistributedGameTime
Or, perhaps this: https://scriptinghelpers.org/questions/71822/how-do-i-create-a-server-age-script-using-this
Hope this helped.
whenever a server starts, you get the EPOCH seconds via os.time() and store them somewhere..
whenever you want to know how old the server is you could do os.time() - storedEPOCHseconds
another thing would be to use a loop that constantly adds 1 to a value after one 1 seond, but that will require constant memory allocation, and depressing performance of your game with each second that passes,
so i personally prefer the first example, and here is how you could implement it...
you could use a module like this:
-in a module script..
local module = {};
local startingTime = os.time();
function module.getServerAge()
return (os.time() - startingTime)
end
--in a script
local mod = require("serverAgeModule")
print(mod.getServerAge())
but will put an emphasis on requiring the module immediately in another script
or put the starting EPOCH value in an IntValue
From what i understood, you want to run a specific code for the first player that enters the game.
You should read this: https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded
Simply get when player joins and then disconnect the function. You'll get a single player, which will be the first one.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Give us more information on what you want to achieve.