How to become a different character after a button click

Hello I am trying to make a character shop, after the player clicks the button, they respawn, I have tried for hours and I can’t seem to find a solution; heres what I have:

Local script:

script.Parent.MouseButton1Click:Connect(function()
	local clone = game.ReplicatedStorage.char:Clone()
	clone.Name = "StarterCharacter"
	clone.Parent = game.StarterPlayer
	game.ReplicatedStorage.re:FireServer()
	
end)

Script:

game.ReplicatedStorage.re.OnServerEvent:Connect(function(player)

player:LoadCharacter()

end)

I know the character has to be named StarterCharacter but it is not working, how can I fix this?

1 Like

You could try using humanoid description. Instead of resetting the player and using a Starter Character. If you’re using a local script, you need to use a normal script, or it won’t work. If you decide to do this route someone could possibly reset at the same time someone changed their avatar and they could have the same custom avatar. So, you should just use humanoid description as it will help your situation a lot.

Ight I will try it. Hopefully it works/

The humanoid description needs to go inside of humanoid. You can add any accessory onto it as well animations.

How do I do that? I am not used to this stuff.

Give me time, i’ll write a script. I’ll edit it and paste the code. Running some test.

1 Like

Thank you, you are not a Losr.

2 Likes

Make this a local script.

-- Variables
local plr = game.Players.LocalPlayer -- Variable for the player
local char = plr.Character -- variable for the character

local Character1 = {
	HatAccessory = 1, -- ID of the accessories.
	NeckAccessory = 1,
	ShouldersAccessory = 1,
	WalkAnimation = "rbxassetid://1", -- ID of the animations.
	JumpAnimation = "rbxassetid://1",
	HeadColor = Color3.new(1, 1, 0.498039), -- Color3 used for body colors.
	TorsoColor = Color3.new(1, 1, 0.498039),
	Tshirt = "123", -- ID of the t shirt
	Shirt = "12345",-- ID of the shirt
	Pants = "1234", -- ID of the pants

}

local Character2 = {
	HatAccessory = 2, -- ID of the accessories.
	NeckAccessory = 2,
	ShouldersAccessory = 2,
	WalkAnimation = "rbxassetid://2", -- ID of the animations.
	JumpAnimation = "rbxassetid://2",
	HeadColor = Color3.new(1, 1, 0.498039), -- Color3 used for body colors.
	TorsoColor = Color3.new(1, 1, 0.498039),
	Tshirt = "123", -- ID of the t shirt
	Shirt = "12345",-- ID of the shirt
	Pants = "1234", -- ID of the pants
}

script.Parent.MouseButton1Click:Connect(function() -- functions on mouse click
	if char.Humanoid:FindFirstChild("HumanoidDescription") then -- Checks if there is a humanoid description
		local HumanoidDescription = char.Humanoid:FindFirstChild("HumanoidDescription")
		-- Accessories
		HumanoidDescription.HatAccessory = Character1.HatAccessory
		HumanoidDescription.NeckAccessory = Character1.NeckAccessory
		HumanoidDescription.ShouldersAccessory = Character1.ShouldersAccessory
		-- Animations
		HumanoidDescription.WalkAnimation = Character1.WalkAnimation
		HumanoidDescription.JumpAnimation = Character1.JumpAnimation
		-- Body Colors
		HumanoidDescription.HeadColor = Character1.HeadColor 
		HumanoidDescription.TorsoColor = Character1.TorsoColor
		-- Clothes
		HumanoidDescription.Shirt = Character1.Shirt
		HumanoidDescription.GraphicTShirt = Character1.Tshirt
		HumanoidDescription.Pants = Character1.Pants
	else -- If no humanoid description
		local HumanoidDescription = Instance.new("HumanoidDescription", char.Humanoid) -- Makes a new instance which is a humanoiddescription
		-- Accessories
		HumanoidDescription.HatAccessory = Character1.HatAccessory
		HumanoidDescription.NeckAccessory = Character1.NeckAccessory
		HumanoidDescription.ShouldersAccessory = Character1.ShouldersAccessory
		-- Animations
		HumanoidDescription.WalkAnimation = Character1.WalkAnimation
		HumanoidDescription.JumpAnimation = Character1.JumpAnimation
		-- Body Colors
		HumanoidDescription.HeadColor = Character1.HeadColor 
		HumanoidDescription.TorsoColor = Character1.TorsoColor
		-- Clothes
		HumanoidDescription.Shirt = Character1.Shirt
		HumanoidDescription.GraphicTShirt = Character1.Tshirt
		HumanoidDescription.Pants = Character1.Pants
	end
end)

You can also use the properties of HumanoidDescription to change the skin color, clothing, animations and body rig type.

2 Likes

Thanks never knew this existed, I will look into it more, a good start.

1 Like
local plr = game.Players.LocalPlayer
local char = plr.Character

local Character1 = {
	HatAccessory = 1, -- ID of the accessories.
	NeckAccessory = 1,
	ShouldersAccessory = 1,
	WalkAnimation = "rbxassetid://1", -- ID of the animations.
	JumpAnimation = "rbxassetid://1",
	HeadColor = Color3.new(1, 1, 0.498039), -- Color3 used for body colors.
	TorsoColor = Color3.new(1, 1, 0.498039),
	Tshirt = "123", -- ID of the t shirt
	Shirt = "12345",-- ID of the shirt
	Pants = "1234", -- ID of the pants

}

local Character2 = {
	HatAccessory = 2, -- ID of the accessories.
	NeckAccessory = 2,
	ShouldersAccessory = 2,
	WalkAnimation = "rbxassetid://2", -- ID of the animations.
	JumpAnimation = "rbxassetid://2",
	HeadColor = Color3.new(1, 1, 0.498039), -- Color3 used for body colors.
	TorsoColor = Color3.new(1, 1, 0.498039),
	Tshirt = "123", -- ID of the t shirt
	Shirt = "12345",-- ID of the shirt
	Pants = "1234", -- ID of the pants
}

script.Parent.MouseButton1Click:Connect(function()
	if char.Humanoid:FindFirstChild("HumanoidDescription") then
		local HumanoidDescription = char.Humanoid:FindFirstChild("HumanoidDescription")
		-- Accessories
		HumanoidDescription.HatAccessory = Character1.HatAccessory
		HumanoidDescription.NeckAccessory = Character1.NeckAccessory
		HumanoidDescription.ShouldersAccessory = Character1.ShouldersAccessory
		-- Animations
		HumanoidDescription.WalkAnimation = Character1.WalkAnimation
		HumanoidDescription.JumpAnimation = Character1.JumpAnimation
		-- Body Colors
		HumanoidDescription.HeadColor = Character1.HeadColor 
		HumanoidDescription.TorsoColor = Character1.TorsoColor
		-- Clothes
		HumanoidDescription.Shirt = Character1.Shirt
		HumanoidDescription.GraphicTShirt = Character1.Tshirt
		HumanoidDescription.Pants = Character1.Pants
	else
		local HumanoidDescription = Instance.new("HumanoidDescription", char.Humanoid)
		-- Accessories
		HumanoidDescription.HatAccessory = Character1.HatAccessory
		HumanoidDescription.NeckAccessory = Character1.NeckAccessory
		HumanoidDescription.ShouldersAccessory = Character1.ShouldersAccessory
		-- Animations
		HumanoidDescription.WalkAnimation = Character1.WalkAnimation
		HumanoidDescription.JumpAnimation = Character1.JumpAnimation
		-- Body Colors
		HumanoidDescription.HeadColor = Character1.HeadColor 
		HumanoidDescription.TorsoColor = Character1.TorsoColor
		-- Clothes
		HumanoidDescription.Shirt = Character1.Shirt
		HumanoidDescription.GraphicTShirt = Character1.Tshirt
		HumanoidDescription.Pants = Character1.Pants
	end
end)

This is for all the other properties. You can make multiple characters.

1 Like

What about shirts? How do I do shirts?

It will be edited in the code above.

1 Like

Thank you so much I appreciate it.

1 Like

You should be able to look in the HumanoidDescription and check out the properties and figure it out. Tell me if this has worked! :smile:

Providing the keys/fields of the table match the properties of a HumanoidDescription instance you can do the following.

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local description = humanoid:GetAppliedDescription()

local button = script.Parent

local customCharacter = {
	--Properties & values go here.
}

button.MouseButton1Click:Connect(function()
	description = description or Instance.new("HumanoidDescription")
	description.Parent = description.Parent or humanoid
	for descriptionProperty, descriptionValue in pairs(customCharacter) do
		description[descriptionProperty] = descriptionValue
	end
	humanoid:ApplyDescription(description)
end)
1 Like

Your code did not work I don’t know why, I will keep experimenting though.

1 Like

Are you putting the ids of accessories or shirts? It can’t be an id of something else. You can go to the avatar shop and click a item and copy the numbers and paste it.

Your script looks fine, I believe you just forgot to apply the description once setting its properties.

humanoid:ApplyDescription(description)

Is the line of code you’re looking for.

1 Like