Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

It is possible to tell if server is new?

Asked by 4 years ago

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

0
Give us more information on what you want to achieve. User#27525 1 — 4y

3 answers

Log in to vote
0
Answered by
Syclya 224 Moderation Voter
4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

Answer this question