Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to stop "/" from divding number of players?

This code is in a local script inside a text label and correctly works when I try to only display the number of players, but I can't seem to find a way to display the number of players out of 10, because obviously roblox things I'm trying to divide the number of players by 10. Is there a way to display "/10" without it dividing the first number?

local players = game.Players:GetPlayers()
local playerCount = script.Parent

while true do
	wait(1)
	playerCount.Text = #players/10
end

2 answers

✓ Accepted answer

If i understand what you're asking you want it to display something like 1/10 or 5/10 on your display?

if thats correct then try the following:

local players = game.Players:GetPlayers()
local playerCount = script.Parent


while true do
	--// we need to keep track of the number of players online each second!
	players = game.Players:GetPlayers()
			
	playerCount.Text = #players.."/10"
	
	wait(1)
end

on the other had if you wanted to work out the percentage of player out of 10 this is how you would do it:

local players = game.Players:GetPlayers()
local playerCount = script.Parent

while true do
	players = game.Players:GetPlayers()
	if(#players > 0) then
		local Percent = #players/10 * 100 -- still dividing but it rounds it out of 100 where you can divide this by 10
		playerCount.Text = Percent.." Percent of Players are not Dancing!"
	else
		playerCount.Text = #players.." Players are online, ...... Hello!?...... Anyone here?"
	end
	wait(1)
end

hope this helps! :)

3 comments

0

You would be better off using a PlayerAdded event on the server and firing an event to update the playerCount rather than using a while true do loop.

0

Yeah i agree, but sometimes i like to do things old fashoned lol and i forgot about that event lol... duh@ me xD

0

Thanks! The first thing was what I wanted, but thanks for the percentage of script example, I'm sure that'll come in handy future foward!

Try concatenating the "/10" using ..

local players = game.Players:GetPlayers()
local playerCount = script.Parent

while true do
    wait(1)
    playerCount.Text = #players .. "/10"
end

This discussion is preserved as it was. New answers, comments, and votes are closed.