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)
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.
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.
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.
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)
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.
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.
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.
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
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)