Character Skin equip

Hello!
I was working on a system for equipping skin and when a player spawns I want it to replace the player’s character to their selected skin which is stored in a value.

When I attempted to create the system, it seem to break the camera and the animate script.

	function Spawnplayer()
		local charloaded = game.ReplicatedStorage.Cosmetics.Skins:FindFirstChild(plr.EquipData.Skin.Value):Clone()
		charloaded.Name = plr.Name
		charloaded.Parent = workspace
		
		for i, ascript in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
			local Selectedscript = ascript:Clone()
			Selectedscript.Parent = charloaded
		end

		plr.Character = charloaded
		plr.Character:MoveTo(TeleportPlayer())
		
		charloaded.Humanoid.Died:Connect(function()
			wait(2)
			Spawnplayer()
		end)
	end
	
	Spawnplayer()

I can’t seem to find anyway around this.

		plr.Character:SetPrimaryPartCFrame(CFrame.new(TeleportPlayer())) --//Assuming that TeleportPlayer returns a Vector3 Value

It’s better to use SetPrimaryPartCFrame rather than MoveTo (And also, you should run MoveTo on the Humanoid and not the Character Model)

Is the script run on the client or server? If it is run on the server, fire a remote event to the client and send the new character model. Then, the client would set the target of the Camera to the new character’s Humanoid.

I fired the remote event to client with the charcater model but it doesn’t seem to fix the camera and doesn’t seem to move the charcater anymore

I seem to find a different way when firing to the client

On the server side character is added to the player and send the model to the clientside to change the camera.

	local function Spawnplayer()
		local charloaded = game.ReplicatedStorage.Cosmetics.Skins:FindFirstChild(plr.EquipData.Skin.Value):Clone()
		charloaded.Name = plr.Name
		charloaded.Parent = workspace
		
		charloaded:SetPrimaryPartCFrame(CFrame.new(TeleportPlayer()))
		
		plr.Character = charloaded
		
		game.ReplicatedStorage.Events.ClientCharacter:FireClient(plr, charloaded)
		

		charloaded.Humanoid.Died:Connect(function()
			wait(2)
			Spawnplayer()
		end)
	end

	Spawnplayer()

On the client side I have the camerasubject set to the camera and the scripts added to the character

game.ReplicatedStorage.Events.ClientCharacter.OnClientEvent:Connect(function(char)
	workspace.Camera.CameraSubject = char
	for i, ascript in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
		local Selectedscript = ascript:Clone()
		Selectedscript.Parent = char
	end
end)

Thank you for your help!

1 Like