Server Time Sign

Are you a beginner at scripting? Have you wanted to make a sign that counts up every second?

Well, this is the tutorial for you.

Enough introduction, let’s make an sign that counts up every second.

1. Make an sign

Time to put your modeling skills in the game! …or not.

If we want to count up something, we need to show it.
You can use anything that has an SurfaceGui > TextLabel

In my preference, I’ll just grab an wooden sign from the Toolbox.

2. Scripting the sign

For the sign to actually work, we need to do some scripting.

First of all, put your script in ServerScriptService.

In the script, we initialize the variables:

local textlabel = workspace.Sign.Text.SurfaceGui.TextLabel -- Getting the TextLabel
local timev -- Intiliazing a variable

We get the TextLabel of our Sign, and we initialize an variable called timev (timevariable)

local textlabel = workspace.Sign.Text.SurfaceGui.TextLabel
local timev

while true do
  task.wait(0.1)
end

Next up, we run a loop every 0.1 seconds
The reason why we add a cooldown is because to prevent lag. 0.1 seconds may sound low but it does the job.

local textlabel = workspace.Sign.Text.SurfaceGui.TextLabel
local timev

while true do
  task.wait(0.1)
  timev = workspace.DistributedGameTime -- Amount of seconds passed since server creation
end

Now, we say that the variable “timev” is the DistributedGameTime.
DistributedGameTime shows how many seconds have passed since the server was created.

local textlabel = workspace.Sign.Text.SurfaceGui.TextLabel
local timev

while true do
  task.wait(0.1)
  timev = workspace.DistributedGameTime
  local moddedtimev = math.modf(timev) -- Make a new variable that rounds up the timev variable
end

Now, we initialize a new variable called moddedtimev that rounds up our timev variable using math.modf().

local textlabel = workspace.Sign.Text.SurfaceGui.TextLabel
local timev

while true do
  task.wait(0.1)
  timev = workspace.DistributedGameTime
  local moddedtimev = math.modf(timev)
  textlabel.Text = "server time: " .. moddedtimev
end
-- Script made by Iogroi2 (the creator of this tutorial, please dont get confused with the credits! :D)

Finally, we change the textlabel’s Text by adding an string that says: "server time: " and then we add our moddedtimev variable.

3. Enjoy your Server Time Sign and explaining the Script

This script is free-to-use so feel free to use it!

Now, let’s explain the Script in one nice section.

We create an new script in ServerScriptService.
We get the TextLabel of our sign and initialize an variable.
Then we add an while true do loop with an 0.1 second cooldown.
We set our variable to the DistributedGameTime.
We get the variable and create an variable that is an rounded up version of our previous variable.
Then we set the TextLabel’s Text to "server time: " and then continue it with our rounded up variable.

So every 0.1 seconds the main part of the Script will loop getting the DistributedGameTime and then rounding the DistributedGameTime up and then use the rounded up DistributedGameTime in the TextLabel’s Text.

Hope you enjoyed and have a nice day!

4 Likes

Make sure to use task.wait not wait since wait is about to get deprecated. More info can be found in this announcement.

3 Likes

I see, I’ll update the post.

Thanks for letting me know!

3 Likes