Issue with my serverstatsus part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    to show the uptime server time in how many players are on the server
  2. What is the issue? Include screenshots / videos if possible!
    I’m trying to make a server status part where it shows the server uptime in how many players are on the server but it’s not working

hers my client script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local updateServerStatsEvent = ReplicatedStorage:WaitForChild("UpdateServerStatsEvent")
local serverTimeLabel = script.Parent:WaitForChild("serverTime"):WaitForChild("num")
local playerCountLabel = script.Parent:WaitForChild("players"):WaitForChild("num")

updateServerStatsEvent.OnClientEvent:Connect(function(serverTime, playerCount)
	serverTimeLabel.Text = "Server Time: " .. serverTime
	playerCountLabel.Text = "Player Count: " .. playerCount
end)

and here’s my server script

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateServerStatsEvent = ReplicatedStorage:WaitForChild("UpdateServerStatsEvent")

local startTime = os.time()

local function updateServerStats()
	local currentTime = os.time()
	local elapsedTime = currentTime - startTime
	local minutes = math.floor(elapsedTime / 60)
	local seconds = elapsedTime % 60
	local serverTime = string.format("%02d:%02d", minutes, seconds)
	local playerCount = #Players:GetPlayers()

	UpdateServerStatsEvent:FireAllClients(serverTime, playerCount)
end

while true do
	updateServerStats()
	wait(1)
end

it looks right
what is not working

Why not just update the text and player count on the server side instead of firing a remote event to all clients?

Still would get the same result but, removes the need for a remote event.

On a side-note: there isn’t a need to involve the server for this long. Instead, use a RemoteFunction that returns the server’s uptime with the time function (not to be confused with os.time) and a Unix timestamp retrieved via os.time or DateTime. The client can request for this value when they first enter the game. A Unix timestamp is sent so the client can correct the server’s reported uptime as time passes with latency. Now that the client has the correct server uptime value in its hands, the client can increment the value itself, avoiding any continued latency in displaying server uptime

You can calculate the server’s population on the client as well

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.