Saving New Clothes After Reset

I need help, how can I make it so that this script will save the clothing after resetting? I don’t want to have the player re-choosing clothing after every reset because this is for an obby.
I hope this makes sense.
Here is my script.

local playername = game.Players.LocalPlayer.Name
local player = workspace:FindFirstChild(""..playername.."")
local button = script.Parent.Parent.Parent

script.Parent.MouseButton1Down:connect(function()
	if player ~= nil then
		button.Enabled = false
		player:FindFirstChild("Pants").PantsTemplate = "rbxassetid://6426724783"
		player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=0000000"
		wait(.3)
		print("Done")
	end
end)

Using CharacterAppearanceLoaded.
Try this:

local playername = game.Players.LocalPlayer.Name
local player = workspace:FindFirstChild(""..playername.."")
local button = script.Parent.Parent.Parent

function Clothing(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Pants = Character:FindFirstChildOfClass("Pants")
		if Pants then	Pants.PantsTemplate = "rbxassetid://6426724783"	end
		local Shirt = Character:FindFirstChildOfClass("Shirt")
		if Shirt then	Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=0000000"	end
	end)
end

script.Parent.MouseButton1Down:connect(function()
	if player ~= nil then
		button.Enabled = false
		player:FindFirstChild("Pants").PantsTemplate = "rbxassetid://6426724783"
		player:FindFirstChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=0000000"
		Clothing(game.Players:GetPlayerFromCharacter(player))
		wait(.3)
		print("Done")
	end
end)

It would also work with CharacterAdded.

Awesome! This worked!
And now I have another question… :sweat_smile:

How would I do that same thing but over here?

local button = script.Parent.Parent.ScrollingFrameW.RedLeo
local debounce = true
local UniEvent = game.ReplicatedStorage:WaitForChild("UniformGiveEventWR")

button.MouseButton1Click:Connect(function()
	if debounce then
		debounce = false
		UniEvent:FireServer()
		wait(1)
		debounce = true
	end
end)

This is the local script above.
This is the server script below.

local Event = Instance.new("RemoteEvent")
Event.Parent = game.ReplicatedStorage
Event.Name = "UniformGiveEventWR"
local Shirt = "rbxassetid://0"
local Pants = "rbxassetid://6487745112"

function GiveUni(plr)
	local GUI = plr.PlayerGui.Leotards.TFrame.NEP
	if plr.leaderstats.Points.Value < 100 then
		GUI.Visible = true
		wait(2) 
		GUI.Visible = false
	elseif plr.leaderstats.Points.Value >= 100 then
		GUI.Visible = false
		local character = plr.Character
		local shirt = character.Shirt
		local pants = character.Pants
		shirt.ShirtTemplate = Shirt
		pants.PantsTemplate = Pants
	end
end

Event.OnServerEvent:Connect(GiveUni)

So, change the server script for this:

function Clothing(Player,PantsId,ShirtId)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Pants = Character:FindFirstChildOfClass("Pants")
		if Pants then	Pants.PantsTemplate = PantsId	end
		local Shirt = Character:FindFirstChildOfClass("Shirt")
		if Shirt then	Shirt.ShirtTemplate = ShirtId	end
	end)
end

local Event = Instance.new("RemoteEvent")
Event.Parent = game.ReplicatedStorage
Event.Name = "UniformGiveEventWR"
local Shirt = "rbxassetid://0"
local Pants = "rbxassetid://6487745112"

function GiveUni(plr)
	local GUI = plr.PlayerGui.Leotards.TFrame.NEP
	if plr.leaderstats.Points.Value < 100 then
		GUI.Visible = true
		wait(2) 
		GUI.Visible = false
	elseif plr.leaderstats.Points.Value >= 100 then
		GUI.Visible = false
		local character = plr.Character
		local shirt = character.Shirt
		local pants = character.Pants
		shirt.ShirtTemplate = Shirt
		pants.PantsTemplate = Pants
		Clothing(plr,Pants,Shirt)
	end
end

Event.OnServerEvent:Connect(GiveUni)

Hm, I tried this and it wouldn’t work. After resetting, the characters clothing would show up blank.

And if I clicked the button from before, and then clicked this one, after resetting the clothes would go back to the first uniform instead of the second. If that makes sense.

Well, plan B: InsertService and LoadAsset:

local Insert = game:GetService("InsertService")
function Clothing(Player,PantsId,ShirtId)
	local Success_Pants, Pants = pcall(Insert.LoadAsset, Insert,PantsId)
	if Success_Pants and Pants then   Pants = Pants:FindFirstChildOfClass("Pants")
	else							print("Error")
	end
	
	local Success_Shirt, Shirt = pcall(Insert.LoadAsset, Insert,ShirtId)
	if Success_Shirt and Shirt then   Shirt = Shirt:FindFirstChildOfClass("Shirt")
	else							print("Error")
	end

	Pants:Clone().Parent = Player.Character
	Shirt:Clone().Parent = Player.Character
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		for i,O in pairs(Character:GetChildren()) do
			if table.find({"Pants","Shirt"},O.ClassName) then	O:Destroy()		end
		end
		Pants:Clone().Parent = Character
		Shirt:Clone().Parent = Character
	end)
end

local Event = Instance.new("RemoteEvent",game:GetService("ReplicatedStorage"))
Event.Name = "UniformGiveEventWR"
local Shirt = 0
local Pants = 6487745112

Event.OnServerEvent:Connect(function(plr)
	local GUI = plr.PlayerGui.Leotards.TFrame.NEP
	if plr.leaderstats.Points.Value < 100 then
		GUI.Visible = true
		wait(2) 
		GUI.Visible = false
	elseif plr.leaderstats.Points.Value >= 100 then
		GUI.Visible = false
		Clothing(plr,Pants,Shirt)
	end
end)

Still not working, I got this error.
OnServerEvent can only be used on the server - Client - ControlWR:29

Change the localscript to a normal script.

Oh, I had pasted it into the wrong script. My mistake.
Now that I switched back to the correct one, I have this error.

ServerScriptService.Womens Tier 1 Scripts.UniformGiveWR:13: attempt to index nil with 'Clone'  -  Server - UniformGiveWR:13

Try this:

function Clothing(Character,PantsId)
	local Shirt = Character:FindFirstChildOfClass("Shirt") 
	if Shirt then		Shirt:Destroy()	end
	local Pants = Character:FindFirstChildOfClass("Pants") 
	if Pants then		Pants.PantsTemplate = "rbxassetid://" .. PantsId	end
end

local Event = Instance.new("RemoteEvent",game:GetService("ReplicatedStorage"))
Event.Name = "UniformGiveEventWR"
local Pants = 6487745112

Event.OnServerEvent:Connect(function(plr)
	local GUI = plr.PlayerGui.Leotards.TFrame.NEP
	if plr.leaderstats.Points.Value < 100 then
		GUI.Visible = true
		wait(2) 
		GUI.Visible = false
	elseif plr.leaderstats.Points.Value >= 100 then
		GUI.Visible = false
		Clothing(plr.Character,Pants)
		plr.CharacterAppearanceLoaded:Connect(function(Character)
			Clothing(Character,Pants)
		end)
	end
end)

The shirt is removed so you don’t get this error:
image

plan B was totally unnecessary :sweat_smile:

Ok so more problems…
Just like before I put on the first uniform from the original script I posted earlier.
Then I changed uniforms to the new one, and reset my character. But my avatar respawned wearing the first uniform instead of the one it was wearing when I reset.