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

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

Asked by 4 years ago

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?

1local players = game.Players:GetPlayers()
2local playerCount = script.Parent
3 
4while true do
5    wait(1)
6    playerCount.Text = #players/10
7end

2 answers

Log in to vote
1
Answered by
TGazza 1336 Moderation Voter
4 years ago

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:

01local players = game.Players:GetPlayers()
02local playerCount = script.Parent
03 
04 
05while true do
06    --// we need to keep track of the number of players online each second!
07    players = game.Players:GetPlayers()
08 
09    playerCount.Text = #players.."/10"
10 
11    wait(1)
12end

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

01local players = game.Players:GetPlayers()
02local playerCount = script.Parent
03 
04while true do
05    players = game.Players:GetPlayers()
06    if(#players > 0) then
07        local Percent = #players/10 * 100 -- still dividing but it rounds it out of 100 where you can divide this by 10
08        playerCount.Text = Percent.." Percent of Players are not Dancing!"
09    else
10        playerCount.Text = #players.." Players are online, ...... Hello!?...... Anyone here?"
11    end
12    wait(1)
13end

hope this helps! :)

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. R_alatch 394 — 4y
0
Yeah i agree, but sometimes i like to do things old fashoned lol and i forgot about that event lol... duh@ me xD TGazza 1336 — 4y
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! MOREHOURSOFFUN 104 — 4y
Ad
Log in to vote
1
Answered by
R_alatch 394 Moderation Voter
4 years ago
Edited 4 years ago

Try concatenating the "/10" using ..

1local players = game.Players:GetPlayers()
2local playerCount = script.Parent
3 
4while true do
5    wait(1)
6    playerCount.Text = #players .. "/10"
7end

Answer this question