Player's portrait mechanic doesnt working

hello, ive been making my game and wanted to add player’s portrait to healthbar background, created a modulescript which will get players character and then insert it into frame where player’s portrait should be

but, player’s character dont appear and i dont know why
module:

local module = {
	configuration = {
		Position = Vector3.new(0, -1, 0);
		Orientation = Vector3.new(0, -180, 0);
		PrimaryPart = "HumanoidRootPart"
	}
}

local hud = script.Parent.Parent
local mainframe = hud:WaitForChild("mainframe")
local portraitframe = mainframe:WaitForChild("stats_hp"):WaitForChild("health_holder"):WaitForChild("portrait")

local lp = game.Players.LocalPlayer

function module:_get_player_portrait()
	local character_portrait = game.Players:CreateHumanoidModelFromUserId(lp.UserId)
	return character_portrait
end

function module:BuildPortrait()
	local character = module:_get_player_portrait()
	character.PrimaryPart = character:WaitForChild(module.configuration.PrimaryPart)
	character.PrimaryPart.Position = module.configuration.Position
	character.PrimaryPart.Orientation = module.configuration.Orientation
	character:PivotTo(portraitframe:WaitForChild("portrait_example").HumanoidRootPart.CFrame)
	character.Parent = portraitframe
end

return module

localscript:

local p = require(libs:WaitForChild("HUD_Portrait"))
p:BuildPortrait()

how it should be:
изображение

how it appears:
изображение

no errors in console
player’s character actually appears in frame, but i dont see it

I think its because your using position, instead of CFrame, try moving the whole model with CFrame, instead of changing the position and orientation individually.

I would also try to get the thumbnail of the player and set it to that.

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local settings = {
	Enum.ThumbnailType.HeadShot,
	Enum.ThumbnailSize.Size420x420
}

local Thumbnail = Players:GetUserThumbnailAsync(Player.UserId, settings[1], settings[2])

Player.PlayerGui.ScreenGui.ImageLabel.Image = Thumbnail

This is just a simpler way, but you do you.

1 Like

i’ve already fixed it, copy of player character just wasnt loaded fully when parented to viewframe and because of that it gets messed up, but thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.