Is there a good way to make a script that gives you hair from the roblox catalog?
COMMUNITY QUESTION
How would i make a Hair giver without Puting all the hairs in Replicated Storage and Cloning?
1 answer
here is something that may help you: https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory
Let's try it with textboxes.
First, make a remote Event and name it "RemoteEvent" and put it in replicated storage
local hairids = {} -- all the hair ids
local TextBox = script.Parent -- textbox
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
TextBox.FocusLost:Connect(
function()
if tonumber(TextBox.Text) ~= nil then -- if it is only numbers then
for i, v in pairs(hairids) do -- looping through the table
local id = tonumber(TextBox.Text)
if id == v then -- if the id is in the table
RemoteEvent:FireServer(player, id) -- firing player and id to server code
end
end
end
end
)
server script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(
function(player, id)
local humanoid = player.Character:WaitForChild("Humanoid")
-- Create the Accessory.
local Hair = Instance.new("Accessory")
Hair.Name = "Hair"
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1, 1.6, 1)
handle.Parent = Hair
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0, -0.24, -0.45)
faceFrontAttachment.Parent = handle
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1, 1.3, 1)
mesh.MeshId = ("rbxassetid://" .. id) -- id
mesh.Parent = handle
-- Attach the Accessory to the humanoid.
humanoid:AddAccessory(Hair)
end
)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you for helping! But is there a way to use Add accessory only with the id of the accessory? Cuz my project has 30 different hairs and i dont want to write 1000 lines of code and i dont want the replicated storage to be filled with accessorys ether cuz the project has many places and i would have to add the accesorys to each place.