Trouble with getting player number

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!
    Getting Player number in a game. The value is stored in server storage and server scripts in server script service is used
  2. What is the issue? Include screenshots / videos if possible!
    Player number updates in a script and is printed correctly but when referenced to . from main script under same server script service parent the value remains 0
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes and mostly I found using a Player.Added or Player.Removing but both scripts cannot find updated player value

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!
g is a refrence to game
Main script:

local pnum =g:GetService("ServerStorage").Pnum.Value

secondary updating script

local pnum = game:GetService("ServerStorage").Pnum.Value
while true do 
	pnum = #game:GetService("Players"):GetPlayers()
	wait(1)
	print(pnum)
end

My first thought while reading this is “…”.

Anyways, you need to change .Pnum.Value to .Pnum and then use .Value everywhere else.


doesn’t work. I updated both script to reference pnum without the value and comparisons to be made using pnum.Value but still no update to value

What does your code look like now?

local g = game
local RS = g:GetService("ReplicatedStorage")
local Gen = RS.General
local Ded= Gen.Died
local ent = Gen.EntG
local mod = require(Gen["Master Module"])
local ps = g.Players
local psdata = ps:GetChildren()
local pnum =g:GetService("ServerStorage").Pnum
local c =Gen.Roundcount
local Status = Gen.Status
local SS = g.ServerStorage
local ms = SS.Maps:GetChildren()
local mnum = #ms
local d1
local work= false
local lob = workspace.Lobby
local alded = false
-- functions
local function Rounder  ()
	work = true
	while true do
	--Intermission
	c=15
	while pnum.Value < 1 do
			print("Too few Players")
			print(pnum.Value)
		wait(1)
		end
		while pnum.Value >=1 and c <=15 and c >=1 do
			c -= 1
			Status = ("Intermission")
			print(Status,c)
			wait(1)
		end

it’s basically an incomplete round system. i finished it as a character starter script by mistake then i’m trying to implement it on server script service

This must be your other script that is the problem. What does the pnum script look like?

it’s the second script at the top

You need to change the .Value in that one as well as I stated above.

That’s it rn

local pnum = game:GetService("ServerStorage").Pnum
while true do 
	pnum = #game:GetService("Players"):GetPlayers()
	wait(1)
	print(pnum)
end

well, not exactly.

local pnum = game:GetService("ServerStorage").Pnum
while true do 
	pnum.Value = #game:GetService("Players"):GetPlayers()
	wait(1)
	print(pnum.Value)
end

This is what I meant.

1 Like

Thx. Yeah I think I did have a problem with the .Value part bec before it was giving me error comparing instance to number

1 Like