How to load a characters custom appearance when they spawn?

So, I thought I solved the problem, but I was wrong. I’m trying to make it so a player will load in with the hair, clothes, etc. that they picked when making their character. The hair loads when they first spawn but if they die and respawn it doesn’t load. How would I fix this?

Code is listed below, the part where I load their character is at the bottom

local DSS = game:GetService("DataStoreService"):GetDataStore("DemonSlayer")

local ServerScriptService = game:GetService("ServerScriptService")

local hNext = game.ReplicatedStorage:WaitForChild("hNext")
local hBack = game.ReplicatedStorage:WaitForChild("hBack")


	------------------------------------------------------------------------Hair change forward

	hNext.OnServerEvent:Connect(function(player)		
	print("test")
	
	
	if player:WaitForChild("Data"):WaitForChild("Hair").Value <= 20 then
	
		player:WaitForChild("Data"):WaitForChild("Hair").Value = player:WaitForChild("Data"):WaitForChild("Hair").Value + 1
		
		local HairValue = player.Data.Hair.Value
		local HairObject = game.ServerScriptService.Hair:FindFirstChild("Hair"..tostring(HairValue))
	print(HairObject)
	
	
	
	local HairValue = player.Data.Hair.Value
	local PlayersHair = player.Character:FindFirstChild("Hair"..tostring(HairValue) - 1)
	PlayersHair:Destroy()
	
	
		HairObject:Clone().Parent = player.Character
		
		
	end	
end)
	
----------------------------------- hair change back	
	
	
	hBack.OnServerEvent:Connect(function(player)		
	print("test")
	
	
	if player:WaitForChild("Data"):WaitForChild("Hair").Value >= 1 then
	
		player:WaitForChild("Data"):WaitForChild("Hair").Value = player:WaitForChild("Data"):WaitForChild("Hair").Value - 1
		
		local HairValue = player.Data.Hair.Value
		local HairObject = game.ServerScriptService.Hair:FindFirstChild("Hair"..tostring(HairValue))
		print(HairObject)
		
		local HairValue = player.Data.Hair.Value
		local PlayersHair = player.Character:FindFirstChild("Hair"..tostring(HairValue) + 1)
		PlayersHair:Destroy()
		
		HairObject:Clone().Parent = player.Character
		
		
	end
end)


-----------------------------------------------------------------


--------------change hair color test


game.ReplicatedStorage.HairColorChange.OnServerEvent:Connect(function(Player)

	local Character = Player.Character
	
	
	local HairColor = Player.Data.HairColor.Value
	
	
	for _, Accessory in pairs(Character:GetChildren()) do	
		if Accessory:IsA("Accessory") then
			local Handle = Accessory:FindFirstChild("Handle")
			-- 	if Handle and Handle:FindFirstChild("HairAttachment") then
			if Handle then
				Handle.Color = HairColor
			end
		end
	end 
end)


---------------------------------------------------------------------------



--------------------------------------load char




game.Players.PlayerAdded:Connect(function(player)
	
	wait(5)
	
	
	local HairValue = player:WaitForChild("Data").Hair.Value
	local HairObject = game.ServerScriptService.Hair:FindFirstChild("Hair"..tostring(HairValue))
	print(HairObject)
	HairObject:Clone().Parent = player.Character
	
end)

You can use a CharacterAdded event (fires everytime the character spawns)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local HairValue = player:WaitForChild("Data").Hair.Value
		local HairObject = game.ServerScriptService.Hair:FindFirstChild("Hair"..tostring(HairValue))
		print(HairObject)
		HairObject:Clone().Parent = char
	end)
end)
1 Like

Thank you so much! I tried something similar but now i understand it better