Issues with updating character appearance in camera system

LocalScript in StarterCharacterScripts:

local Config            = require(game.ReplicatedStorage.Settings)
local HeadOffset        = Config.HeadOffset
local FieldOfView       = Config.FieldOfView
local ToggleKey         = Config.ToggleKey
local MouseIcon         = Config.MouseIcon
local MouseIconEnabled  = Config.MouseIconEnabled

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera

local X,Y = 0,0

if not MouseIconEnabled then
	UIS.MouseIconEnabled = false
else
	Mouse.Icon = MouseIcon
end

Camera.CameraType = Enum.CameraType.Scriptable
Camera.FieldOfView = FieldOfView
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter

local function inputChanged (input, _gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local Delta = Vector2.new(input.Delta.X, input.Delta.Y)

		X = math.clamp(X - Delta.Y, -80, 80) 
		Y = (Y - Delta.X) % 360
	end
end

local function renderStepped (deltaTime)
	Camera.CFrame = CFrame.new(Character.Head.Position)
	* CFrame.Angles(0, math.rad(Y), 0)
	* CFrame.Angles(math.rad(X), 0, 0)
    * HeadOffset

	Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.Position)
    * CFrame.Angles(0, math.rad(Y), 0)
end

local function updateCharacter ()
	for _, part in pairs(Character:GetChildren()) do
		
		if part.Name == "Head" then
			part.LocalTransparencyModifier = 1
		end
		
		if part:IsA("Accessory") then
			part.Handle.LocalTransparencyModifier = 1
		end
	end
	print("Character updated")
end

if Character then
    updateCharacter()
end --This block is what I'm having issues with

UIS.InputChanged:Connect(inputChanged)
RS.RenderStepped:Connect(renderStepped)

It works when the player spawns for the first time; my issue is that when updateCharacter() fires upon respawning the character appearance is not fully loaded & it effectively does nothing. I attempted to use two separate checks: “if Character then” in conjuction with “Player.CharacterAppearanceLoaded:Connect(updateCharacter)” but that made it run twice on respawn. It technically works, but it isn’t very efficient. I’m not the best programmer, so please bear with me.

How about replacing

if Character then
    updateCharacter()
end

with

task.spawn(function()
repeat task.wait() until Player:HasAppearanceLoaded()
updateCharacter()
end)

Didn’t work. Same respawning issue.

It doesn’t run at all or it doesn’t load everything when it runs?

It works as expected the first time the player spawns. If the player dies afterward, updateCharacter() will run before their accessories are loaded & it won’t make them invisible.

1 Like

Odd, my own tests show the same thing. It seems it does actually work, but then all the accessories just magically load up…

An idea is to list all of the accessories you got on the first load in an array – then use Character.ChildAdded to check whenever a new accessory loads in, then if it can be found, do the code there:

local Config            = require(game.ReplicatedStorage.Settings)
local HeadOffset        = Config.HeadOffset
local FieldOfView       = Config.FieldOfView
local ToggleKey         = Config.ToggleKey
local MouseIcon         = Config.MouseIcon
local MouseIconEnabled  = Config.MouseIconEnabled

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera

local X,Y = 0,0

if not MouseIconEnabled then
	UIS.MouseIconEnabled = false
else
	Mouse.Icon = MouseIcon
end

local currentListOfAccessories = {}

Camera.CameraType = Enum.CameraType.Scriptable
Camera.FieldOfView = FieldOfView
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter

local function inputChanged (input, _gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local Delta = Vector2.new(input.Delta.X, input.Delta.Y)

		X = math.clamp(X - Delta.Y, -80, 80) 
		Y = (Y - Delta.X) % 360
	end
end

local function renderStepped (deltaTime)
	Camera.CFrame = CFrame.new(Character.Head.Position)
		* CFrame.Angles(0, math.rad(Y), 0)
		* CFrame.Angles(math.rad(X), 0, 0)
		* HeadOffset

	Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.Position)
		* CFrame.Angles(0, math.rad(Y), 0)
end

local function updateCharacter ()
	for _, part in pairs(Character:GetChildren()) do

		if part.Name == "Head" then
			part.LocalTransparencyModifier = 1
		end

		if part:IsA("Accessory") then
			part.Handle.LocalTransparencyModifier = 1
			if not table.find(currentListOfAccessories, part.Name) then
				table.insert(currentListOfAccessories, part.Name)
			end
		end
	end
	print("Character updated")
end

task.spawn(function()
	repeat task.wait() until Player:HasAppearanceLoaded()
	updateCharacter()
end)

Character.ChildAdded:Connect(function(child)
	if table.find(currentListOfAccessories, child.Name) then
		child.Handle.LocalTransparencyModifier = 1
	end
end)
UIS.InputChanged:Connect(inputChanged)
RS.RenderStepped:Connect(renderStepped)
1 Like

Tried it. The respawn issue persists.

1 Like

Can you modify these lines and see what they print on output?

if part:IsA("Accessory") then
			part.Handle.LocalTransparencyModifier = 1
			if not table.find(currentListOfAccessories, part.Name) then
				table.insert(currentListOfAccessories, part.Name)
				warn("ADDING: " .. part.Name)
			end
		end
Character.ChildAdded:Connect(function(child)
	warn("HI CHILDADDED RAN ON: " .. child.Name)
	if table.find(currentListOfAccessories, child.Name) then
		warn("AND YES I FOUND IT ON LIST: " .. child.Name)
		child.Handle.LocalTransparencyModifier = 1
	else
		warn("UMMM... DIDNT FIND IT IN LIST: " .. child.Name)
	end
end)
1 Like

What I did: reset character after spawning in

17:31:00.918 ADDING: Accessory (Meshes/hoodieAccessory) - Client - Camera:61
[RESPAWNED HERE]
17:31:06.634 HI CHILDADDED RAN ON: Body Colors - Client - Camera:73
17:31:06.634 UMMM… DIDNT FIND IT IN LIST: Body Colors - Client - Camera:78
17:31:06.716 HI CHILDADDED RAN ON: CharacterMesh - Client - Camera:73
17:31:06.717 UMMM… DIDNT FIND IT IN LIST: CharacterMesh - Client - Camera:78
17:31:06.717 HI CHILDADDED RAN ON: Shirt - Client - Camera:73
17:31:06.717 UMMM… DIDNT FIND IT IN LIST: Shirt - Client - Camera:78
17:31:06.717 HI CHILDADDED RAN ON: Roblox 2.0 Right Arm - Client - Camera:73
17:31:06.717 UMMM… DIDNT FIND IT IN LIST: Roblox 2.0 Right Arm - Client - Camera:78
17:31:06.717 HI CHILDADDED RAN ON: Pants - Client - Camera:73
17:31:06.717 UMMM… DIDNT FIND IT IN LIST: Pants - Client - Camera:78
17:31:06.717 HI CHILDADDED RAN ON: CharacterMesh - Client - Camera:73
17:31:06.718 UMMM… DIDNT FIND IT IN LIST: CharacterMesh - Client - Camera:78
17:31:06.718 HI CHILDADDED RAN ON: CharacterMesh - Client - Camera:73
17:31:06.718 UMMM… DIDNT FIND IT IN LIST: CharacterMesh - Client - Camera:78
17:31:06.718 HI CHILDADDED RAN ON: CharacterMesh - Client - Camera:73
17:31:06.718 UMMM… DIDNT FIND IT IN LIST: CharacterMesh - Client - Camera:78
17:31:06.718 HI CHILDADDED RAN ON: Accessory (Meshes/hoodieAccessory) - Client - Camera:73
17:31:06.718 UMMM… DIDNT FIND IT IN LIST: Accessory (Meshes/hoodieAccessory) - Client - Camera:78

Could you send what it prints out on the console, including the first spawn (no reset yet)?

1 Like

Put a task.wait() before the script.