-- Made by Speakerpro2, fixed by qunjz and Thomasluigi07.

local teamLines= true -- show lines under team names
local divisionLines= false -- show vertical lines between leaderstats

local font="Arial"
local fontSize= 14

local backgroundTransparency= 0.4 -- the transparency of the background
local backgroundColor= Color3.new(160/255,160/255,160/255) --the color of the background

local borderSize= 0 -- thickness of the border
local borderColor= Color3.new(BrickColor.Black()) -- the color of the border

local position= "Top_right"
--[[
Top_left
Top_middle
Top_right
Left
Center
Right
Bottom_left
Bottom_middle
Bottom_right
]]










game:GetService("StarterGui"):SetCoreGuiEnabled("PlayerList",false)
local colors={"Bright red","Bright blue","Earth green","Bright violet","Bright orange","Bright yellow","Light reddish violet","Brick yellow"}
local childs=workspace.GetChildren
local find=workspace.FindFirstChild
local serviceP=game:GetService("Players")
local serviceT=game:GetService("Teams")
local me=serviceP.LocalPlayer
local connect=workspace.Changed.connect
local a=connect(workspace.Changed,function(value)print(value)end)
local disconnect=a.disconnect
disconnect(a)
local connections={}



local getColor=function(name)
	local value=0
	for i=1,#name do
		local byte=string.byte(string.sub(name,i,i))
		local value2=#name-i+1
		if#name%2==1 then
			value2=value2-1
		end
		if value2%4>=2 then
			byte=-byte
		end
		value=value+byte
	end
	return BrickColor.new(colors[(value%8)+1]).Color
end



local new=function(class)
	local item=Instance.new(class)
	if class=="TextLabel"then
		item.TextXAlignment="Left"
		item.TextYAlignment="Top"
		item.Size=UDim2.new(0,1,0,1)
		item.BackgroundTransparency=1
		item.Font=font
		item.TextSize=fontSize
		item.TextColor3=BrickColor.White().Color
		item.TextStrokeColor3=BrickColor.Black().Color
		item.ZIndex=9
	end
	return function(prop)
		for k,v in pairs(prop)do
			if type(k)=="number"then
				v.Parent=item
			else
				item[k]=v
			end
		end
		return item
	end
end



if script:FindFirstChild("Gui")then script.Gui:Destroy()end
local screen=new'ScreenGui'{Parent=script,Name="Gui"}
local text=new'TextLabel'{Parent=screen,Visible=false}
local frame=new'Frame'{Parent=screen,BackgroundTransparency=backgroundTransparency,BackgroundColor3=backgroundColor,BorderSizePixel=borderSize,BorderColor3=borderColor,ZIndex=8}
script:FindFirstChild("Gui").IgnoreGuiInset = true

function getValue(value)
	if value.ClassName=="BoolValue"then
		return tostring(value.Value)
	elseif value.ClassName=="BrickColorValue"then
		return value.Value.Name
		--elseif value.ClassName=="CFrameValue"then
		--return"0"
	elseif value.ClassName=="Color3Value"then
		return math.floor(255*value.Value.r)..","..math.floor(255*value.Value.g)..","..math.floor(255*value.Value.b)
	elseif value.ClassName=="DoubleConstrainedValue"then
		return""..(math.floor(value.ConstrainedValue*100)/100)
	elseif value.ClassName=="IntConstrainedValue"then
		return""..value.ConstrainedValue
	elseif value.ClassName=="IntValue"then
		return""..value.Value
	elseif value.ClassName=="NumberValue"then
		return""..(math.floor(value.Value*100)/100)
	elseif value.ClassName=="ObjectValue"then
		return value.Value and value.Value.Name or""
	elseif value.ClassName=="RayValue"then
		return"{"..math.floor(value.Value.Origin.x*100)/100 ..","..math.floor(value.Value.Origin.y*100)/100 ..","..math.floor(value.Value.Origin.z*100)/100 .."},{"..math.floor(value.Value.Direction.x*100)/100 ..","..math.floor(value.Value.Direction.y*100)/100 ..","..math.floor(value.Value.Direction.z*100)/100 .."}"
	elseif value.ClassName=="StringValue"then
		return value.Value
	elseif value.ClassName=="Vector3Value"or value.ClassName=="CFrameValue"then
		return math.floor(value.Value.x*100)/100 ..","..math.floor(value.Value.y*100)/100 ..","..math.floor(value.Value.z*100)/100
	end
	return"0"
end



function newList()
	for k,v in pairs(connections)do
		disconnect(v)
	end
	connections={}
	text.Text="Player"
	text.Parent=screen
	wait()
	frame:ClearAllChildren()
	local y=0
	local xT=text.TextBounds.x
	local ySize=text.TextBounds.y
	local listLabel=new'TextLabel'{Parent=frame}
	local us=childs(serviceP)for i=#us,1,-1 do if us[i].ClassName~="Player"then table.remove(us,i)end end
	local teams=childs(serviceT)for i=#teams,1,-1 do if teams[i].ClassName~="Team"then table.remove(teams,i)end end
	local allStats={}
	local allStats2=1

	for k,v in pairs(us)do text.Text=v.Name..' 'if text.TextBounds.x>xT then xT=text.TextBounds.x end end
	for k,v in pairs(teams)do text.Text=v.Name..' 'if text.TextBounds.x>xT then xT=text.TextBounds.x end end

	for k,v in pairs(us)do
		local s=find(v,'leaderstats')
		if s then
			for k2,v2 in pairs(childs(s))do
				if string.find(v2.ClassName,'Value')then
					if not allStats[v2.Name..v2.ClassName]then
						allStats[v2.Name..v2.ClassName]={allStats2,v2,xT}
						local xS=0
						text.Text=v2.Name..' 'if text.TextBounds.x>xS then xS=text.TextBounds.x end
						text.Text=getValue(v2)..' 'if text.TextBounds.x>xS then xS=text.TextBounds.x end
						xT=xT+xS+10
						allStats2=allStats2+1
					end
				end
			end
		end
	end

	for k,v in pairs(allStats)do
		v[3]=(v[3]+10)/xT
		local sLabel=new'TextLabel'{Parent=frame,Text=v[2].Name,Position=UDim2.new(v[3],0,0,0),Size=UDim2.new(0,1,0,ySize)}
		if divisionLines then
			new'Frame'{Parent=frame,ZIndex=9,Size=UDim2.new(0,1,1,0),BorderSizePixel=0,BackgroundColor3=borderColor,Position=UDim2.new(v[3],0,0,0)}
		end
	end

	y=y+1

	if screen.AbsoluteSize.y-30<=ySize*(#us+#teams+2)then
		ySize=math.floor((screen.AbsoluteSize.y-30)/(#us+#teams+2))
	end

	if#teams==0 then
		if allStats2>1 then
			listLabel.Text="Player"
		else
			listLabel.Text="Player List"
		end
		for k,v in pairs(us)do
			local nLabel=new'TextLabel'{Parent=frame,Text=v.Name,Position=UDim2.new(0,0,0,ySize*y),TextColor3=getColor(v.Name)}

			local stats=find(v,'leaderstats')
			if stats then
				for k2,v2 in pairs(childs(stats))do
					if string.find(v2.ClassName,"Value")then
						listLabel.Text="Player"
						local sLabel=new'TextLabel'{Parent=frame,Text=getValue(v2),Size=UDim2.new(0,1,0,ySize)}
						sLabel.Position=UDim2.new(allStats[v2.Name..v2.ClassName][3],0,0,y*ySize)
						table.insert(connections,connect(v2.Changed,function()sLabel.Text=getValue(v2)end))
					end
				end
			end

			y=y+1
		end
	else
		listLabel.Text="Team"
		local have={}
		for k,v in pairs(teams)do
			y=y+.5
			local tLabel=new'TextLabel'{Parent=frame,Text=v.Name,Position=UDim2.new(0,0,0,ySize*y),TextColor3=v.TeamColor.Color,TextStrokeTransparency=0}
			if teamLines then
				new'Frame'{Parent=frame,ZIndex=10,Size=UDim2.new(1,0,0,1),Position=UDim2.new(0,0,0,ySize*(y+1)),BorderSizePixel=0,BackgroundColor3=v.TeamColor.Color}
			end

			y=y+1
			for k2,v2 in pairs(us)do
				if v2.TeamColor==v.TeamColor and(not v2.Neutral)and(not have[v2.Name])then
					have[v2.Name]=true
					local pLabel=new'TextLabel'{Parent=frame,Text=" "..v2.Name,Position=UDim2.new(0,0,0,ySize*y),TextColor3=v.TeamColor.Color}

					local stats=find(v2,'leaderstats')
					if stats then
						for k3,v3 in pairs(childs(stats))do
							if string.find(v3.ClassName,"Value")then
								local sLabel=new'TextLabel'{Parent=frame,Text=getValue(v3),TextColor3=v.TeamColor.Color,--[[Position=UDim2.new(allStats[v3.Name..v3.ClassName][1]/allStats2,0,0,ySize*y),]]Size=UDim2.new(0,1,0,ySize)}
								sLabel.Position=UDim2.new(allStats[v3.Name..v3.ClassName][3],0,0,y*ySize)
								table.insert(connections,connect(v3.Changed,function()sLabel.Text=getValue(v3)end))
							end
						end
					end

					y=y+1
				end
			end
		end

		local nLabel
		for k,v in pairs(us)do
			if not have[v.Name]then
				if not nLabel then
					y=y+.5
					nLabel=new'TextLabel'{Parent=frame,Text="Neutral",Position=UDim2.new(0,0,0,ySize*y),TextColor3=BrickColor.White().Color,TextStrokeTransparency=0}
					if teamLines then
						new'Frame'{Parent=frame,ZIndex=10,Size=UDim2.new(1,0,0,1),Position=UDim2.new(0,0,0,ySize*(y+1)),BorderSizePixel=0,BackgroundColor3=BrickColor.White().Color}
					end
					y=y+1
				end
				local pLabel=new'TextLabel'{Parent=frame,Text=" "..v.Name,Position=UDim2.new(0,0,0,ySize*y),TextColor3=getColor(v.Name)}

				local stats=find(v,'leaderstats')
				if stats then
					for k2,v2 in pairs(childs(stats))do
						if string.find(v2.ClassName,"Value")then
							local sLabel=new'TextLabel'{Parent=frame,Text=getValue(v2),--[[Position=UDim2.new(allStats[v2.Name..v2.ClassName][1]/allStats2,0,0,ySize*y),]]Size=UDim2.new(0,1,0,ySize)}
							sLabel.Position=UDim2.new(allStats[v2.Name..v2.ClassName][3],0,0,y*ySize)
							table.insert(connections,connect(v2.Changed,function()sLabel.Text=getValue(v2)end))
						end
					end
				end

				y=y+1
			end
		end
	end

	if allStats2==1 then
		text.Text="List "
		xT=xT+text.TextBounds.x+80
	end
	y=y+.5
	frame.Size=UDim2.new(0,xT,0,y*ySize)
	if position=="Top_left"then
		frame.Position=UDim2.new(0,10,0,10)
	elseif position=="Top_middle"then
		frame.Position=UDim2.new(.5,-xT/2,0,10)
	elseif position=="Top_right"then
		--	frame.Position=UDim2.new(1,-xT-10,0,10)
		frame.Position = UDim2.new(1, -278, 0, 10)
		frame.Size = UDim2.new(frame.Size.X.Scale,268,frame.Size.Y.Scale,frame.Size.Y.Offset)
	elseif position=="Left"then
		frame.Position=UDim2.new(0,10,.5,-y*ySize/2)
	elseif position=="Center"then
		frame.Position=UDim2.new(.5,-xT/2,.5,-y*ySize/2)
	elseif position=="Right"then
		frame.Position=UDim2.new(1,-xT-10,.5,-y*ySize/2)
	elseif position=="Bottom_left"then
		frame.Position=UDim2.new(0,10,1,-y*ySize-10)
	elseif position=="Bottom_middle"then
		frame.Position=UDim2.new(.5,-xT/2,1,-y*ySize-10)
	elseif position=="Bottom_right"then
		frame.Position=UDim2.new(1,-xT-10,1,-y*ySize-10)
	else
		frame.Position=UDim2.new(1,-xT-10,0,10)
	end
	text.Parent=nil
end





local canUpdate=true
function update()
	if canUpdate then
		canUpdate=false
		wait(.5)
		newList()
		canUpdate=true
	end
end
function leaderstats(child)
	wait()
	if child.Name=="leaderstats"then
		update()
	end
end
connect(serviceT.ChildAdded,function(child)
	if child.ClassName=="Team"then
		connect(child.Changed,update)
		update()
	end
end)
connect(serviceT.ChildRemoved,function(child)
	if child.ClassName=="Team"then
		update()
	end
end)
connect(serviceP.ChildAdded,function(child)
	if child.ClassName=="Player"then
		connect(child.Changed,update)
		connect(child.ChildAdded,leaderstats)
		connect(child.ChildRemoved,leaderstats)
		update()
	end
end)
connect(serviceP.ChildRemoved,function(child)
	if child.ClassName=="Player"then
		update()
	end
end)
for k,v in pairs(childs(serviceT))do
	if v.ClassName=="Team"then
		connect(v.Changed,update)
	end
end
for k,v in pairs(childs(serviceP))do
	if v.ClassName=="Player"then
		connect(v.Changed,update)
		connect(v.ChildAdded,leaderstats)
		connect(v.ChildRemoved,leaderstats)
	end
end
newList() 

Lua online compiler

Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.

Taking inputs (stdin)

OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.

name = io.read("*a")
print ("Hello ", name)

About Lua

Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.

Syntax help

Variables

  • By default all the variables declared are global variables
  • If the variables are explicitly mentioned as local then they are local variables.
  • Lua is a dynamically typed language and hence only the values will have types not the variables.

Examples

-- global variables
a = 10

-- local variables

local x = 30
Value TypeDescription
numberRepresents numbers
stringRepresents text
nilDifferentiates values whether it has data or not
booleanValue can be either true or false
functionRepresents a sub-routine
userdataRepresents arbitary C data
threadRepresents independent threads of execution.
tableCan hold any value except nil

Loops

1. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition)
do
--code
end

2. Repeat-Until:

Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.

repeat
   --code
until( condition )

3. For:

For loop is used to iterate a set of statements based on a condition.

for init,max/min value, increment
do
   --code
end

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.

optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end