Putting player icons on screen

I am trying to put player icons on screen as players join but it seems to only work in local scripts but if I use it in local scripts other players can’t see their icons. Does anyone know how to put player icons in a server script that shows up on everyones screen?

Code:

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent
local tpData
local totalPlayers = 0

tpEvent.OnServerEvent:Connect(function(plr, tpData0)
	tpData = tpData0
end)

game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	if tpData then
		print("tpData is good")
		totalPlayers += 1
		print(plr)
		print(totalPlayers)
		local ThumbType = Enum.ThumbnailType.HeadShot
		local ThumbSize = Enum.ThumbnailSize.Size150x150
		local plrAvatar, isReady = Players:GetUserThumbnailAsync(plr.UserId, ThumbType, ThumbSize)
		print(plr.UserId)
		local string0 = tostring(totalPlayers)
		print(string0)
		local image =  game.StarterGui.StartScreen["ImageLabel" .. string0]
		image.Image = plrAvatar
	end
	if totalPlayers == tpData then
		wait(3)
		local test = Instance.new("Part", workspace)
		test.Position = Vector3.new(0, 2.5, 0)
		wait(5)
		test.Color = Color3.new(1, 0, 0)
	end
end)

You must make a Remote Event to call whenever a new player joins/leaves the game
This must be done on the Server Side

Do you mean to call a remote event from the server script to a local script. Because if so, only that player would see the icon on their screen but I need everyone in the server to see.

On the server when a player joins/leave you will send that info to Everyone using “:FireAllClients()”. This will then tell every player in the game

This function should work Server Side. Are you sure your ImageLabel is displaying correctly?
Using a RemoteEvent to show other players your icon could cause insecurities like changing the image to something else.

What should I check to make sure its displaying correctly?

the current script will not work server-sided because the server does not have a display nor can it access player displays

I double checked your code, it might be because you’re changing the GUI that’s in StarterGui. When a player joins, they get their own copy of it in PlayerGui, changing it wont do anything.

Still doen’t work and has no errors.

Local

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent

tpEvent.OnClientEvent:Connect(function(plr, totalPlayers)
	print(plr.Name)
	print(totalPlayers)
	local ThumbType = Enum.ThumbnailType.HeadShot
	local ThumbSize = Enum.ThumbnailSize.Size150x150
	local plrAvatar, isReady = Players:GetUserThumbnailAsync(plr.UserId, ThumbType, ThumbSize)
	local string0 = tostring(totalPlayers)
	local image =  game.StarterGui.StartScreen["ImageLabel" .. string0]
	image.Image = plrAvatar
end)

Server:

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent
local tpData
local totalPlayers = 0

tpEvent.OnServerEvent:Connect(function(plr, tpData0)
	tpData = tpData0
end)

game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	if tpData then
		print("tpData is good")
		totalPlayers += 1
		tpEvent:FireAllClients(plr, totalPlayers)
	end
	if totalPlayers == tpData then
		wait(3)
		local test = Instance.new("Part", workspace)
		test.Position = Vector3.new(0, 2.5, 0)
		wait(5)
		test.Color = Color3.new(1, 0, 0)
	end
end)

sorry about that, i forgot that you can do PlayerAdded client sided, follow what this man is doing

Is there anyway around this? Like a global GUI.

That seems hacky, a suggestion I have would be firing the remote event on the serverside and sending the player’s user ID to the client. Then the client would go inside their own player’s PlayerGui and make the effect there. It’s usually better to make effects like these on the client side anyway.

I tried that with the code I replied with above. It doesn’t return any errors and all prints are good but it just doesn’t work. Could you take a look?

Oh I forgot to check that, you need to change the GUI in the player’s PlayerGui, not the StarterGui. The StarterGui what the Player copies to their PlayerGui when they join in and it isn’t what they currently see.

1 Like

I have been testing with a friend and what happens is my icon of myself is on the right and on my friends screen his icon is on the left but on both our screens the oppisite sides are still blank template pictures instead of showing us both.

Server Code

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent
local tpData
local totalPlayers = 0

tpEvent.OnServerEvent:Connect(function(plr, tpData0)
	tpData = tpData0
end)

game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	if tpData then
		print("tpData is good")
		totalPlayers += 1
		tpEvent:FireAllClients(plr, totalPlayers)
	end
	if totalPlayers == tpData then
		wait(3)
		local test = Instance.new("Part", workspace)
		test.Position = Vector3.new(0, 2.5, 0)
		wait(5)
		test.Color = Color3.new(1, 0, 0)
	end
end)

Local Code:

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent

tpEvent.OnClientEvent:Connect(function(plr, totalPlayers)
	print(plr.Name)
	print(totalPlayers)
	local ThumbType = Enum.ThumbnailType.HeadShot
	local ThumbSize = Enum.ThumbnailSize.Size150x150
	local plrAvatar, isReady = Players:GetUserThumbnailAsync(plr.UserId, ThumbType, ThumbSize)
	local string0 = tostring(totalPlayers)
	local image =  game.Players[plr.Name]:WaitForChild("PlayerGui").StartScreen["ImageLabel" .. string0]
	image.Image = plrAvatar
end)

You’re only changing one image to your own, if you wanted to change both you’d have to store the first player that joined and send it over to the next so they know both players UserID and can update both.

Another suggestion is just doing all of this on the ClientSide, unless you need the tpdata check there.

1 Like

How was my friend who got in the server before my not able to see my icon, because if he loaded in first then his icon would come up and then when I joined it should have loaded my icon on to his screen but it just left it blank.

Side note, where would I store the UserID’s? I was thinking it could be an array on the server side

This is what I came up with.

Server Code:

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent
local tpData
local totalPlayers = 0
local UserIDs = {}

tpEvent.OnServerEvent:Connect(function(plr, tpData0)
	tpData = tpData0
end)

game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	if tpData then
		print("tpData is good")
		totalPlayers += 1
		table.insert(UserIDs, totalPlayers, plr.UserId)
		tpEvent:FireAllClients(UserIDs, totalPlayers, plr)
	end
	if totalPlayers == tpData then
		wait(3)
	-local test = Instance.new("Part", workspace)
		test.Position = Vector3.new(0, 2.5, 0)
		wait(5)
		test.Color = Color3.new(1, 0, 0)
	end
end)

Local Code:

local Players = game:GetService("Players")
local tpEvent = game:GetService("ReplicatedStorage").teleportData
local imageEvent = game:GetService("ReplicatedStorage").imageEvent

tpEvent.OnClientEvent:Connect(function(UserIDs, totalPlayers, plr)
	for i = 1, totalPlayers, 1 do
		print(plr.Name)
		print(totalPlayers)
		print(UserIDs[i])
		local ThumbType = Enum.ThumbnailType.HeadShot
		local ThumbSize = Enum.ThumbnailSize.Size150x150
		local plrAvatar, isReady = Players:GetUserThumbnailAsync(UserIDs[i], ThumbType, ThumbSize)
		local string0 = tostring(i)
		local image =  game.Players[plr.Name]:WaitForChild("PlayerGui").StartScreen["ImageLabel" .. string0]
		image.Image = plrAvatar
	end
end)