How to give person gear via script

Hello,
I’ve looked all around the internet to find a tutorial for giving roblox gear via script but I cannot find one. (Gear meaning actual gear you can put on, not tools.) Could someone either please help me direct a source or help me script something where when a player clicks a button, it equips them with gear.

I know this may be complicated as gear can be welded to certain parts of the body and can contain different elements.

1 Like

Gear like hats? Can you elaborate on that or provide an example gear?

Yes, like hats and other Roblox items that you can put on through the avatar page on Roblox.

I’d start with:

https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory

And if that doesn’t work then: (ignore the post name, it’s helpful code)

And if you’re still experiencing issues let me know!

1 Like

aren’t roblox gear work like tools? just like search it up in the tool bar and see what you find

Alright, I put this script under StarterCharacterScripts like it asked for, and defined a button within a GUI, and made it so when the button is clicked, it should use the humanoid:AddAccessory to add the accessory to the player. This did not work for some reason. Any idea why?

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local button = game.StarterGui.ToolsUI.ContentFrame:WaitForChild("Headband")

-- Create the Accessory.
local clockworksShades = Instance.new("Accessory")
clockworksShades.Name = "ClockworksShades"

local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1,1.6,1)
handle.Parent = clockworksShades

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://1577360"
mesh.TextureId = "rbxassetid://1577349"
mesh.Parent = handle

-- Attach the Accessory to the humanoid.
button.Activated:Connect(function()
	humanoid:AddAccessory(clockworksShades)
end)

You might need to parent it to the character and clone it

How would I go about doing that? Sorry, I am new to this type of scripting… I mainly do UI scripting.

You are trying to access the StarterGui’s button, while you should access the PlayerGui’s button, you could do something like this i guess

-- get the player
local player = game.Players:GetPlayerFromCharacter(playerModel)
-- and get the button via the PlayerGui
local button = player:WaitForChild("PlayerGui").ToolsUI.ContentFrame:WaitForChild("Headband")
1 Like

This worked! Thank you so much!

1 Like