Hi everyone!
I’m stuck again working on the script for my GUI HUD.
I used a free model to put the image of the avatar of the player onscreen.
Then I added some stuff to make it flash and play a sound when you take damage.
The problem is that this code is based upon the thumbnail image of the avatar from the website.
What would I use to update it with the players live appearance so that if they unlock a hat or a different face in the game, that it updates on their HUD as well?
Here is what I currently use:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local Player = Players.LocalPlayer
local Character = Workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local UI = Player.PlayerGui:WaitForChild("UI")
local Elements = UI:WaitForChild("Elements")
local User = Elements:WaitForChild("User")
local Avatar = User:WaitForChild("Avatar")
Avatar.Image = "https://www.roblox.com/headshot-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
local player = game.Players.LocalPlayer
local function onHealthChanged()
if Humanoid.Health <= 0 then
Avatar.BackgroundTransparency = 0
wait(10)
Avatar.BackgroundTransparency = 1
print("Dead!")
else
print("Damage Taken")
Avatar.BackgroundTransparency = 0
game.Workspace.Sounds.Oof:Play()
wait(0.1)
Avatar.BackgroundTransparency = 1
end
end
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Pattern: update once now, then any time the health changes
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Connect our spawn listener; call it if already spawned
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end
I also tried using Players:GetCharacterAppearanceAsync, but I couldn’t figure out how to get it onto the HUD. It would throw an error that said it was an unexpected URL
Thanks for reading as always