I cant figure out why this wont work, Its supposed to update everytime the stringvalue gets changed to a different name.
-- Variables
local players = game:GetService("Players")
-- Create a StringValue to hold the player name
local playerNameValue = script:FindFirstChild("PlayerName")
-- Function to update the ImageLabel with the specified player's avatar
local function updateImageLabel(playerName)
-- If playerName is nil or empty, do nothing
if not playerName or playerName == "" then
return
end
local player = players:FindFirstChild(playerName)
if player then
-- Get the player's avatar image ID
local userId = player.UserId
local ThumbType = Enum.ThumbnailType.AvatarThumbnail
local ThumbSize = Enum.ThumbnailSize.Size150x150
local PlayerImage, isReady = players:GetUserThumbnailAsync(userId, ThumbType, ThumbSize)
-- Set the ImageLabel's Image property to the player's avatar
script.Parent.Image = PlayerImage
end
end
-- Function to handle changes to the PlayerName value
local function onPlayerNameChanged()
updateImageLabel(playerNameValue.Value)
end
-- Listen for changes to the PlayerName value
if playerNameValue then
playerNameValue:GetPropertyChangedSignal("Value"):Connect(onPlayerNameChanged)
-- Initial setup
if playerNameValue.Value then
updateImageLabel(playerNameValue.Value)
end
else
warn("PlayerName StringValue not found")
end