-- Get the custom character model
local customCharacter = game.ServerStorage.CustomCharacterModel:Clone() -- Replace with the path to your custom model
-- Function to replace player character
local function replaceCharacter(player)
-- Wait for player's character to load
player.CharacterAdded:Wait()
-- Check if player exists and is loaded
if player.Character then
local oldCharacter = player.Character
-- Save player accessories
local accessories = {}
for _, accessory in pairs(oldCharacter:GetChildren()) do
if accessory:IsA("Accessory") then
table.insert(accessories, accessory:Clone())
end
end
-- Destroy the old character
oldCharacter:Destroy()
-- Clone and parent the custom character model
local newCharacter = customCharacter:Clone()
newCharacter.Parent = workspace
-- Equip accessories to the new character
for _, accessory in ipairs(accessories) do
accessory.Parent = newCharacter
end
-- Ensure the humanoid root part is not anchored
newCharacter.HumanoidRootPart.Anchored = false
-- Position the new character
newCharacter:SetPrimaryPartCFrame(CFrame.new(oldCharacter.HumanoidRootPart.Position))
-- Assign the new character to player
player.Character = newCharacter
end
end
-- Connect function to player spawn event
game.Players.PlayerAdded:Connect(function(player)
-- Call the function to replace character on spawn
player.CharacterAdded:Connect(function()
replaceCharacter(player)
end)
end)
-- Call the function for players already in the game
for _, player in ipairs(game.Players:GetPlayers()) do
replaceCharacter(player)
end
I have this script that allows accessory handles to be mesh parts with a custom character (because GetCharacterAppearanceAsync does not have mesh part handles), could someone please review it?