On R6 avatars, when I wear another outfit in-game, the overhead GUI works fine. But on R15 avatars, I can see that on outfit change, the character temporarily gets deleted and cloned again, therefore I lose the cloned elements. Any way to keep the overhead gui on the character ?
script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UpdateOverheadGUIEvent = ReplicatedStorage:WaitForChild("UpdateOverheadGUI")
-- Function to create and set up the overhead GUI for a player
local function createOverheadGUI(player)
player.CharacterAdded:Connect(function(character)
local head = character:WaitForChild("Head")
local clonedGUI = ReplicatedStorage.OverheadGUI:Clone()
clonedGUI.Parent = head
end)
end
-- Connect the PlayerAdded event to create the overhead GUI for each new player
Players.PlayerAdded:Connect(createOverheadGUI)
-- Create overhead GUIs for all players currently in the game
for _, player in pairs(Players:GetPlayers()) do
createOverheadGUI(player)
end
-- Function to update the overhead GUI text
local function updateOverheadGUI(player, newText)
if player.Character then
local head = player.Character:FindFirstChild("Head")
if head then
local overheadGUI = head:FindFirstChild("OverheadGUI")
if overheadGUI then
local textLabel = overheadGUI:FindFirstChild("TextLabelStatus")
if textLabel then
textLabel.Text = newText
end
end
end
end
end
-- Listen for the remote event
UpdateOverheadGUIEvent.OnServerEvent:Connect(function(player, newText)
updateOverheadGUI(player, newText)
end)