Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Would I Make Custom Character's Clothes Still Save After Death?

I've had an idea of how to come across this but my script does not seem to work. When the player spawns in, I give them custom clothes but when they die, they return back to their original state before they spawned/got the clothes(no clothes). And yes, I have Load Character Appearance off.

In my script, when the player dies, it puts the clothes in the character's body but when the character respawns the clothes disappear and the folder is empty. Also, when the character respawns, it adds another folder with the character's name which is empty so it cancels out the other folder making it inaccessible.

Is there any possible way to do this? I've ran out of ideas. Sorry if my code is a little sloppy.

Script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local playergui = p:WaitForChild("PlayerGui")
		local playeraccessories = Instance.new("Folder", script)
		playeraccessories.Name = p.name.."'s Accessories"
		
		p:WaitForChild("Spawned").Changed:Connect(function(newvalue)
			if newvalue == true then
				playergui.SpawnClothes:Destroy(p)
				game.StarterGui.SpawnClothes:Destroy()	
			for _, children in pairs(char:GetChildren()) do
			if children:IsA("Shirt") or children:IsA("Pants") then
				local clonedclothes = children:Clone()
				clonedclothes.Parent = playeraccessories
				end
			end	
			end	
		end)
			
		hum.Died:Connect(function()
		while true do
			wait(1.5)
if char and not char:FindFirstChild("Shirt") or not char:FindFirstChild("Pants") then
	for _, clothes in pairs(playeraccessories:GetChildren()) do
		if playeraccessories.Name == p.Name.."'s Accessories" then
						local c = clothes:Clone()
						c.Parent = char
						end
					end
				end
			end
		end)		
	end)	
end)


1 answer

I would use a if not loop to make sure that section of the code only runs once. For example,

if not script:FindFirstChild(p.Name.."'s Accessories") then -- checks to see if the folder exists
 local playeraccessories = Instance.new("Folder", script)
        playeraccessories.Name = p.name.."'s Accessories"
end

This discussion is preserved as it was. New answers, comments, and votes are closed.