Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i make a customCharacter selecter?

Asked by 5 years ago
Edited 5 years ago

the ploblem is i have welds on my customcharacter like shoulder pads and here u deal with it:

local remote = game.ReplicatedStorage.RemoteFunction

function remote.OnServerInvoke(player, msg)
    if msg == "Change1" then
        local char = workspace:FindFirstChild(player.Name)
        if char ~= nil and char:FindFirstChild("Humanoid") ~= nil then
            -- Remove Prior Accessories
            for i, v in pairs(char:GetDescendants()) do
                if v.ClassName == "Accessory" then
                    v:Destroy()
                end
            end
            -- Remove Face (Not Required, Only if you have another to force the user to wear)
            for i, v in pairs(char:GetDescendants()) do
                if v.Name == "face" then
                    v:Destroy()
                end
            end
            -- Changes Shirt, if applicable
            if char:FindFirstChild("Shirt") ~= nil then
                char.Shirt.ShirtTemplate = "rbxassetid://0" -- Asset Id of Shirt
            end
            -- Changes Pants, if applicable
            if char:FindFirstChild("Pants") ~= nil then
                char.Pants.PantsTemplate = "rbxassetid://0" -- Asset Id of Pants
            end
            -- Changes Body Colors, if applicable, not required
            local color = char:FindFirstChild("Body Colors") -- Each Color Ranges from 0 to 255
            if color ~= nil then
                color.HeadColor3 = Color3.new(0, 0, 0)
                color.LeftArmColor3 = Color3.new(0, 0, 0)
                color.RightArmColor3 = Color3.new(0, 0, 0)
                color.LeftLegColor3 = Color3.new(0, 0, 0)
                color.RightLegColor3 = Color3.new(0, 0, 0)
                color.TorsoColor3 = Color3.new(0, 0, 0)
            end
            -- Adds New Hair or Other Accessory
            local accessory = Instance.new("Accessory")
            local hair = Instance.new("Part")
            local mesh = Instance.new("SpecialMesh")
            local weld = Instance.new("Weld")

            accessory.Name = "Hair"
            accessory.Parent = char

            hair.Name = "Handle"
            hair.CanCollide = false
            hair.Anchored = true
            hair.Size = Vector3.new(1,1,1)
            hair.Parent = accessory

            weld.Parent = hair
            weld.Part0 = hair
            weld.Part1 = char.Head
            weld.C0 = CFrame.new(0, 0, 0) -- Test in Studio to Determine correct offset
            hair.Anchored = false

            mesh.MeshId = "rbxassetid://0" -- Mesh Id
            mesh.TextureId = "rbxassetid://0" -- Texture Id
            mesh.Scale = Vector3.new(1, 1, 1)
            mesh.Parent = hair
            wait()
            return true -- This is the second part of the remote function, firing to the client
        end
    end
end
1
lol hellmatic 1523 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This code should be placed within the current function

local accessory2 = Instance.new("Accessory")
local pad = Instance.new("Part")
local mesh2 = Instance.new("SpecialMesh")
local weld2 = Instance.new("Weld")

accessory2.Name = "Shoulder Pads"
accessory2.Parent = char

pad.Name = "Handle"
pad.CanCollide = false
pad.Anchored = true
pad.Size = Vector3.new(1,1,1)
pad.Parent = accessory2

weld2.Parent = pad
weld2.Part0 = pad
weld2.Part1 = char.Head
weld2.C0 = CFrame.new(0, 0, 0)
pad.Anchored = false

mesh2.MeshId = "rbxassetid://0" -- Mesh Id
mesh2.TextureId = "rbxassetid://0" -- Texture Id
mesh2.Scale = Vector3.new(1, 1, 1)
mesh2.Parent = pad

You need to make sure each newly defined variable has a separate name from those previously used.

Just copy the mesh / texture id of the shoulder pads into the corresponding strings and alter the C0 of the weld (which determines the offset from the part in-game)

If the "Shoulder Pads" are all separate parts, you will have to weld them individually to the player:

-- Part 1
local pad1 = Instance.new("Part")
local mesh2 = Instance.new("SpecialMesh")
local weld2 = Instance.new("Weld")

pad1.Name = "Shoulder Pads 1"
pad1.CanCollide = false
pad1.Anchored = true
pad1.Size = Vector3.new(1,1,1)
pad1.Parent = char

weld2.Parent = pad1
weld2.Part0 = pad1
weld2.Part1 = char.Head
weld2.C0 = CFrame.new(0, 0, 0)
pad1.Anchored = false

mesh2.MeshId = "rbxassetid://0" -- Mesh Id
mesh2.TextureId = "rbxassetid://0" -- Texture Id
mesh2.Scale = Vector3.new(1, 1, 1)
mesh2.Parent = pad1

-- Part 2
local pad2 = Instance.new("Part")
local mesh3 = Instance.new("SpecialMesh")
local weld3 = Instance.new("Weld")

pad2.Name = "Shoulder Pads 2"
pad2.CanCollide = false
pad2.Anchored = true
pad2.Size = Vector3.new(1,1,1)
pad2.Parent = char

weld3.Parent = pad2
weld3.Part0 = pad2
weld3.Part1 = char.Head
weld3.C0 = CFrame.new(0, 0, 0)
pad2.Anchored = false

mesh3.MeshId = "rbxassetid://0" -- Mesh Id
mesh3.TextureId = "rbxassetid://0" -- Texture Id
mesh3.Scale = Vector3.new(1, 1, 1)
mesh3.Parent = pad2

The above examples both create the welds manually, as well as the should pads, though you can also clone the should pads to the player directly from Storage (however, the welds will still need to be manually input):

local pad = game.ServerStorage.ShoulderPads:Clone()
local weld2 = Instance.new("Weld")

pad.Anchored = true
pad.Parent = char

weld2.Parent = pad
weld2.Part0 = pad
weld2.Part1 = char.Head
weld2.C0 = CFrame.new(0, 0, 0)
pad.Anchored = false
Ad

Answer this question