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

Getting a players shirt/pants to change from a GUI with filtering enabled?

Asked by 6 years ago

Hello, I've been having some issues with getting my uniform giver to work correctly with filtering enabled. It only works in roblox studio, so I assume it's a filtering enabled issue, but I need my filtering to be enabled.

It works by walking up to a locker, and a GUI prompts you for what clothes you want. This is the script I have inside of each button that does not seem to be working.

local shirtId = script.Parent.Shirt.ShirtTemplate --shirt template location

function onClicked(player)


    print(player.Name.." clicked on Uniform Giver")


    local foundShirt = player.Character:FindFirstChild("Shirt") -- Tries to find Shirt
    if not foundShirt then -- if there is no shirt
        print("No shirt found, creating for "..player.Name)
        local newShirt = Instance.new("Shirt",player.Character) --creates new shirt
        newShirt.Name = "Shirt" --new shirt name is shirt
    else if foundShirt then -- if there is a shirt
        print("Shirt found, reconstructing for "..player.Name)
        player.Character.Shirt:remove() --removes shirt
        local newShirt = Instance.new("Shirt",player.Character) --creates new shirt
        newShirt.Name = "Shirt" --new shirtname is shirt
    end
    end

    player.Character.Shirt.ShirtTemplate = shirtId --changes shirt Id to the template's Id
end


script.Parent.MouseButton1Down:connect(onClicked) --calls function onclick of gui

1 answer

Log in to vote
0
Answered by
Kulh 125
6 years ago
    local character = player.Character
    if character then
        local asset = game.InsertService:LoadAsset(assetId):GetChildren()[1]
        asset.Parent = character
    end
end

This should work in a Server Script (Normal Script) placed in ServerScriptService Change "assetId" to the shirt ID

Hopefully this helps you work with what you're trying to do.

Such as clicking the button, to fire this script and add the cloth.

0
"assetId" shouldn't have quotes, jsut a number string, which would end up as green numbers between the parenthesis Kulh 125 — 6y
Ad

Answer this question