I've tried a bunch of ideas to give my code an accurate player count, but so far, nothing has worked out. The piece of code that's gotten me closest looks something like this - 'val' being a number variable that stores the number of players. I've set it up so that it checks every .15 seconds.
while true do
wait(0.15)
game.Players.PlayerAdded(function(player)
val.Value = val.Value + 1
end)
game.Players.PlayerRemoving(function(player)
val.Value = val.Value - 1
end
end)
This code works in simple tests, but on a real server, it ends up adding/removing over 100 to the value instead of just one. Is there a more simple way I could get the number of players currently on the server. Any answers are greatly appreciated.

2 comments
You should probably explain why your code works (:GetPlayers() returns a list of players and #list returns the length of a list)
I was having trouble with this too