function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local score = Instance.new("IntValue")
score.Name = "Score"
score.Value = 0
local play = Instance.new("IntValue")
play.Name = "Playing"
play.Value = 0
play.Parent = newPlayer
score.Parent = stats
stats.Parent = newPlayer
repeat wait() until newPlayer.Character
newPlayer.Character.Humanoid.Died:connect(function() death(newPlayer) end)
end
function death(player)
if player.Playing.Value==1 then
player.Playing.Value=0
else
assert(false,"Error in DEATH")
end
end
function numplaying()
local newtab={}
for qw,wq in pairs(game.Players:GetChildren()) do
if wq:FindFirstChild("Playing")~=nil then
if wq.Playing.Value==1 then
table.insert(newtab,wq)
elseif wq.Playing.Value==0 then
for re,er in pairs(newtab) do
if er==wq then
table.remove(newtab,re)
end
end
end
end
end
return #newtab
end
while true do
_G.peopleplaying=numplaying()--keep running numplaying
wait()
end
game.Players.PlayerAdded:connect(onPlayerEntered)
for _, v in pairs(game.Players:GetPlayers()) do
onPlayerEntered(v)
end
|