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

How do I create a gui button that changes what my character is wearing?

Asked by 6 years ago

As in a button in an inventory. I do not know how I would make it so that on click, my character equips a hat, or a package, etc.

0
I think you should really learn scripting before trying to do something difficult. Florian27 76 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Make sure it is a LocalScript.

local shirt = "" -- shirt id
local pants = "" -- pants id
local Gui = script.Parent --change the location of Gui wherever it is
local Player = game.Players.LocalPlayer.Character --This is the player's character 

Gui.MouseButton1Down:connect(function()
    Player.ShirtId = shirt  --I'm not sure if ShirtId is the correct property
    Player.PantsId = pants
end)
Ad
Log in to vote
0
Answered by 6 years ago
local gui = script.Parent
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character

local Accessory = gui:WaitForChild("Accessory") --Or where ever your hat is stored
local package = game.Workspace.Package:GetChildren() --Or where ever your package is

gui.MouseButton1Down:connect(function()
    for i,v in pairs(character:GetChildren()) do
        if v:IsA("Shirt") then
            v.ShirtTemplate = "DESIRED SHIRT ID" --For example: rbxassetid://1275157403
        elseif v:IsA("Pants") then
            v.PantsTemplate = "DESIRED PANTS ID" --For example: rbxassetid://1293205847
        end
    end)

    --Do this to add a hat:
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:AddAccessory(Accessory)
    end

    --Do this to add a package:
    for i,v in pairs(package) do
        v:Clone().Parent = character
    end
end)

Put this in a LocalScript inside of your GUI button

Answer this question