Custom Playerlist not updating in game

My player list doesn’t seem to be correctly updating while playing the game, it only updates every time you reset, instead of in real time. It’s supposed to show new players joining and leaving the game and the GUI should automatically refresh, instead it’s just frozen until you re spawn and doesn’t give you an updated version of who’s on the server. Does anyone know what I am doing wrong? Any help is much appreciated

Code
game.Players.PlayerAdded:connect(update)
 
mouse.KeyDown:connect(function(key)
    if string.lower(key) == "l" then
        if ld.Visible then
            game.Lighting.Blur.Size = 0
            script.Parent:FindFirstChild("Open"):Play()
            ld.Visible = not ld.Visible
        elseif not ld.Visible then
            ld.Visible = true
            game.Lighting.Blur.Size = 15
            script.Parent:FindFirstChild("Close"):Play()
        end
    end
end)
 


local listed = {}

local function Update(tag)

    listed[player.Name] = tag

local function Remove(player)
    if listed[player.Name] then 
        listed[player.Name]:Destroy()
        listed[player.Name] = nil
    	end
	end

game.Players.PlayerRemoving:Connect(Remove)
	update()
	

What it looks like


The player online part works fine. Sometimes it’ll say there are 5 players online when the GUI will only show 10 because it doesn’t refresh properly.

1 Like

I’m not sure I understand your code completely. For starters, you might want to fix your formatting so others here can understand your problem easier.

From what I do see, you’re calling the update function but not providing the tag argument, which is likely setting listed[Player.Name] to nil. Wouldn’t you also want to call Remove() when a player is leaving, as opposed to update? You’re also calling the update function with a lowercase U, you should note that functions are case sensitive and must be typed how they are defined.

In simple terms, you should add the player to the list when they join, and remove them when they leave. There may be other factors that you may have to consider based on your situation.

It’s hard to give you a solution when I don’t completely understand your code and some bits are missing. There are some obvious improvements to be made, however.

1 Like

Edit I ended up solving this. All I had to do was move the update() to where it refreshes

1 Like