Alright here is the code:
local frame = script.Parent
local num = frame.Players
local template = frame.Template
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character then
player1 = v
end
end
function Joining(player)
num.Value = num.Value + 1
local slotnum = num.Value
local slot = template:Clone()
slot.Parent = frame
slot.Name = "Slot"..slotnum
slot.Position = UDim2.new(0,0,0,55*num.Value)
slot.Text = player1.Name
slot.Visible = true
end
function Leaving(player)
for i,label in pairs(frame:GetChildren()) do
if label then
if string.find(label.Name,"Slot") then
if label.Text == player.Name then
label:Destroy()
num.Value = num.Value - 1
else
end
end
end
end
end
script.Parent.Parent.Submit.MouseButton1Down:connect(Joining)
game.Players.PlayerRemoving:connect(Leaving)
And I am getting this error: Workspace.Part.SurfaceGui.Hosts.ListScript:18: attempt to index global 'player1' (a nil value)
I just want it to print the player's name onto the surfacegui.

2 comments
I got this error: Workspace.Part.SurfaceGui.Hosts.ListScript:19: '' expected near 'end'
You should tab your code correctly, then. You have an
endthat's not attached to any block.