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

Best way to refresh player's avatar?

I'm sure that this is possible, but I'm not sure what the best way to do it is. In my game, I'm going to have uniform changers, mostly with department uniforms (Police, Fire Dept, etc.)
What I'm wondering is the best way for a uniform changer to change to their normal avatar. I'm not sure exactly how to do this.

What my first thought to do (but was a bad way to do it) is copy their inventory to a temporary location, save their location, and then reset them, teleport them back to that position, and give their items back. This, obviously, is not the best way to do it, but I'm not sure if there's any better way.

Any suggestions or documentation links would be very helpful! Thank you.

Edit: I've found out about Player:LoadCharacter() I am not sure if this removes anything from the player's inventory/backpack, or anything inside of the Player object inside game.Players.

1 answer

Hey i don't know if you can refresh avatar but i would do it like this:

local team_clothing = workspace:WaitForChild("Folder")-- Folder you want to have team accessories in
local character = "Player's character"
local clothing = { -- If instance is one of these then it will destroy it
	"Shirt",
	"Pants",
	"ShirtGraphic",
	"Accessory"
}

local function remove_clothing(character_f) -- removes clothing function
	for _, players_cloth in pairs(character_f:GetChildren()) do -- gets children of character
		for _, removeable_cloth in pairs(clothing) do -- do function for every variable in clothing table
			if players_cloth:IsA(removeable_cloth) then -- if cloth is that variable then
				players_cloth:Destroy() -- destroy it
			end
		end
	end
end

local function add_teams_clothing(character_f, folder_f) -- adds clothing for this character in that folder
	for _, cloth in pairs(folder_f:GetChildren()) do -- for every single children in the folder
		cloth:Clone().Parent = character_f -- Clone it and put it into the parent
	end
end

2 comments

0

Thank you, I'll try this out!

0

When you call LoadCharacter() the player's backpack does indeed get wiped, but doing LoadCharacter() does not count as a Humanoid death.

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