How can I make this script update UI

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a player UI that updates when someone join
Story

the UI still works when someone joins, lets say that client 1 joins before client 2. Client 1 can see his avatar and name, but when client 2 joins he can see client 1 and 2 avatar but client 1 cant.

  1. What is the issue? Include screenshots / videos if possible!
    I can’t seem to get it to update the UI when someone else joins.
  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using a while true do but when the player joins the leaderboard copys the name 3 times.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Code
local Players = game:GetService("Players")
local AmountOfPlayers = #Players:GetPlayers()
local ServerStorage = game.ServerStorage
local TOuch = game:GetService("UserInputService").TouchEnabled
local Keyboard = game:GetService("UserInputService").KeyboardEnabled
local Gamepad = game:GetService("UserInputService").GamepadEnabled
local Player
local Player1 
local Player2 
local Player3 
local Player4
local Player1ID
local Player2ID
local Player3ID 
local Player4ID
local Cooldown = 10

function Update()

end
	Players.PlayerAdded:Connect(function(Player)
		AmountOfPlayers = AmountOfPlayers + 1
		game.ServerStorage.ServerSidedStorage.Users.Users.Value = AmountOfPlayers
		if AmountOfPlayers == 1 then
			game.StarterGui.Main.Frame.Client1.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
			if Keyboard == true then
				print("😀 Client 1 | ⌨ Keyboard Enabled / PC")
				game.StarterGui.Main.Frame.Client1.Platform.Text = "⌨"
				game.StarterGui.Main.Frame.Client1.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client1.Data.platform.Value.Value = 1
			end
			if TOuch == true then
				print("Client 1 | Touch Enabled / Mobile")
				game.StarterGui.Main.Frame.Client1.Platform.Text = "📱"
				game.StarterGui.Main.Frame.Client1.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client1.Data.platform.Value.Value = 2
			end
			if Gamepad == true then
				print("Client 1 | Gamepad Enabled / XBOX")
				game.StarterGui.Main.Frame.Client1.Platform.Text = "🎮"
				game.StarterGui.Main.Frame.Client1.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client1.Data.platform.Value.Value = 3
			end
		end
		if AmountOfPlayers == 2 then
			game.StarterGui.Main.Frame.Client2.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
			if Keyboard == true then
				print("😀 Client 2 | ⌨ Keyboard Enabled / PC")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "⌨"
				game.StarterGui.Main.Frame.Client2.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client2.Data.platform.Value.Value = 1
			end
			if TOuch == true then
				print("Client 2 | Touch Enabled / Mobile")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "📱"
				game.StarterGui.Main.Frame.Client2.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client2.Data.platform.Value.Value = 2
			end
			if Gamepad == true then
				print("Client 2 | Gamepad Enabled / XBOX")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "🎮"
				game.StarterGui.Main.Frame.Client2.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client2.Data.platform.Value.Value = 3
			end
		end
		if AmountOfPlayers == 3 then
			game.StarterGui.Main.Frame.Client2.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
			if Keyboard == true then
				print("😀 Client 3 | ⌨ Keyboard Enabled / PC")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "⌨"
				game.StarterGui.Main.Frame.Client3.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client3.Data.platform.Value.Value = 1
			end
			if TOuch == true then
				print("Client 3 | Touch Enabled / Mobile")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "📱"
				game.StarterGui.Main.Frame.Client3.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client3.Data.platform.Value.Value = 2
			end
			if Gamepad == true then
				print("Client 3 | Gamepad Enabled / XBOX")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "🎮"
				game.StarterGui.Main.Frame.Client3.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client3.Data.platform.Value.Value = 3
			end
		end
		if AmountOfPlayers == 4 then
			game.StarterGui.Main.Frame.Client2.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
			if Keyboard == true then
				print("😀 Client 4 | ⌨ Keyboard Enabled / PC")
				Player.PlayerGui.Main.Frame.Client4.Platform.Text = "⌨"
				game.StarterGui.Main.Frame.Client4.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client2.Data.platform.Value.Value = 1
			end
			if TOuch == true then
				print("Client 4 | Touch Enabled / Mobile")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "📱"
				game.StarterGui.Main.Frame.Client4.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client4.Data.platform.Value.Value = 2
			end
			if Gamepad == true then
				print("Client 4 | Gamepad Enabled / XBOX")
				game.StarterGui.Main.Frame.Client2.Platform.Text = "🎮"
				game.StarterGui.Main.Frame.Client4.TextLabel.Text = Player.Name
				ServerStorage.ServerSidedStorage.Users.Client4.Data.platform.Value.Value = 3
			end
		end
end)	

Players.PlayerRemoving:Connect(function(Player)
	AmountOfPlayers = AmountOfPlayers - 1
	game.ServerStorage.ServerSidedStorage.Users.Users.Value = AmountOfPlayers
end)

*this is in server storage / server script storage

2 Likes

You are only changing the UI to the recently joined player. If you want to update the others players, you can either use a table and loop through every players UI. Or you can use a Remote to FireAllClients. And have them update their own UIs when a new Player Joins.

1 Like

But the script is updating the screen gui instead of the player gui

StarterGui will only replicate once, and that is when the Player initially joins. Any changes after will not occur. So I suggest altering the players ScreenGui, once they join and do as mentioned before.

So should I update the player gui or screen gui.

PlayerGui is a Folder that every Player has, which holds their ScreenGuis.

To clarify, StarterGui only replicates once, and any changes after will not occur in already present Players Gui. The ScreenGuis which are replicated from StarterGui are placed in PlayerGui. Here is an Example :

Do :

game.Players.PlayerAdded:Connect(function(player)
    local gui = player.PlayerGui.ScreenGui.TextLabel.Text = "WhatEverYouType"
end

Don’t :

game.Players.PlayerAdded:Connect(function(player)
   local gui = game.StarterGui.ScreenGui.TextLabel.Text = "WhatEverYouType"
end

I did, but it says “screengui is not a valid member of player”, i’ll try it again

Use :WaitForChild(" ")


and its not a child of Player its Player->PlayerGui->ScreenGui