I’m trying to update the image in the GUI above the character’s head by clicking a button in the player’s gui. I can’t get this to work, and it’s returning no errors unfortunately! Any solutions? I’m quite new to scripting, so I probably donked something up LOL.
The button on the right has an “ImageURL” attribute that holds the id of the image to be transplanted into the “CommunicationImage”
-- UpdateCommunicationImage Script
-- This script updates the player's Head.MemberGui.CommunicationImage.Image to the image of the button clicked.
local Players = game:GetService("Players")
-- Function to update the communication image
local function updateCommunicationImage(player, imageUrl)
-- Wait for the player's character to load
local character = player.Character or player.CharacterAdded:Wait()
-- Ensure the character has a head
local head = character:FindFirstChild("Head")
if not head then return end
-- Find the MemberGui in the head
local memberGui = head:FindFirstChild("MemberGui")
if not memberGui then return end
-- Find the CommunicationImage inside the Frame
local communicationImage = memberGui:FindFirstChild("CommunicationImage")
if not communicationImage then return end
-- Update the image
communicationImage.Image = imageUrl
end
-- Connect to the PlayerAdded event to handle players as they join
Players.PlayerAdded:Connect(function(player)
-- Connect to the player's character appearance
player.CharacterAdded:Connect(function(character)
local button = game.StarterGui.CustomizeGui.Menu.ExamplePage.ScrollingFrame:FindFirstChild("Example", true)
if button then
button.MouseButton1Click:Connect(function()
-- Assuming the button has an attribute "ImageUrl" storing the URL of the image to set
local imageUrl = button:GetAttribute("ImageUrl")
updateCommunicationImage(player, imageUrl)
end)
end
end)
end)
-- Iterate through all existing players and attach the logic
for _, player in Players:GetPlayers() do
player.CharacterAdded:Connect(function(character)
end)
end