I am trying to make a GUI text label and a image label which shows the username and the avatar of a player in a team. This team will only have a limit of 1 player. However, when I tested out, it works only when there is one person in the server. However, since this is a multiplayer game, I need it to work for everyone. Is there anyway I can fix that problem? Here is the code for both below.
Script for the Username
while true do
wait(0.05)
if game.StarterGui.ScreenGui.Procedure.Visible then
local players = game.Players:GetPlayers()
for i,v in pairs(players) do
if v.Team.Name == "Host" then
script.Parent.Text = v.Name
else
script.Parent.Text = "Username"
end
end
end
end
Script for the avatar picture
while true do
task.wait(0.05)
if game.StarterGui.ScreenGui.Procedure.Visible then
local players = game.Players:GetPlayers()
for i,v in pairs(players) do
if v.Team.Name == "Host" then
local userId = v.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
script.Parent.Image = content
else
script.Parent.Image = "rbxasset://textures/ui/GuiImagePlaceholder.png"
end
end
end
end
Your way of getting ScreenGui is currently setting to the one where it holds a copy and clones to the PlayerGui, Everything updated is on PlayerGui instead of StarterGui, hence why it doesn’t update
local playerSV = game:GetService("Players")
local player_crv = playerSV.LocalPlayer
local ScreenGUI = player_crv.PlayerGui.ScreenGui --or directly from "script.Parent" if your script was inside a ScreenGui
maybe it’s because how you checked the boolean of visible, either that you are missing the check on the if statement which is only assigning to the property, if you need to check a value, it should include double equals otherwise it won’t read, following with the datatype that you are checking with e.g bool_val.Value == false
(i edited the response incase for some people new to scripting)
and make sure the script’s parent is ScreenGUI, not anything else
if PlayerGui.ScreenGui.Procedure.Visible then
--it should have "== true" or "== false"
if PlayerGui.ScreenGui.Procedure.Visible == true then