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

How to change Players looks using a Rig mid-game?

Asked by 2 years ago

So the explanation is kinda vague because I don't fully know what I'm doing, but I've got a Rig called "StarterCharacter" that is located in the "StarterPlayer" folder and I've got it so that the player's avatar is set to that Rig.

I'm trying to change the players avatar mid-game by editing the Rig and it changes the properties I want, but won't update the player's look.

local gate = script.Parent
local rigshirt = game.StarterPlayer.StarterCharacter.shirt
local rigtrousers = game.StarterPlayer.StarterCharacter.Trousers

gate.Touched:Connect(function()
    rigshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=584017370"
    rigtrousers.PantsTemplate = "http://www.roblox.com/asset/?id=584017819"
end)

Any suggestions are appreciated :)

1 answer

Log in to vote
0
Answered by 2 years ago

You're changing the StarterCharacter. This gets put into a players character once they join. To change their shirt and pants. You'd need to find the players character and change it from their Character Model.

Hopefully this code will clear some stuff up. P.S - Put this into a default script. LocalScripts do not execute in Workspace.

Gate = script.Parent

Gate.Touched:Connect(function(hit)

    if hit and hit.Parent:FindFirstChild("Humanoid") then --This checks if the part that touched exists, then checks if it's a Player.

        local Shirt = hit.Parent:FindFirstChild("Shirt") --Finds Shirt.
        if not Shirt then --If there's no shirt. It creates a new one inside of the character. (Debugging)

            local CreateShirt = Instance.new("Shirt") 
            CreateShirt.Parent = hit.Parent
            CreateShirt.Name = "Shirt"
            CreateShirt.ShirtTemplate = "http://www.roblox.com/asset/?id=584017370" --Changes to selected Shirt.

        else --If there is a Shirt, It'll execute the following code.

            Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=584017370" --Changes to selected Shirt.

        end


        local Pants = hit.Parent:FindFirstChild("Pants") --Finds Pants.
        if not Pants then --If there's no pants. It creates a new one inside of the character. (Debugging)

            local CreatePants = Instance.new("Pants") 
            CreatePants.Parent = hit.Parent
            CreatePants.Name = "Pants"
            CreatePants.PantsTemplate = "http://www.roblox.com/asset/?id=584017819" --Changes to selected Pants.

        else --If there are pants, It'll execute the following code.

            Pants.PantsTemplate = "http://www.roblox.com/asset/?id=584017819" --Changes to selected Pants.

        end
    end

end)

Alternative (Without Debugging Code [If you want concise, fast code]):

Gate = script.Parent

Gate.Touched:Connect(function(hit)

    if hit and hit.Parent:FindFirstChild("Humanoid") then --This checks if the part that touched exists, then checks if it's a Player.

        local Shirt = hit.Parent:FindFirstChild("Shirt") --Finds Shirt.
        Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=584017370" --Changes to selected Shirt.

        local Pants = hit.Parent:FindFirstChild("Pants") --Finds Pants.
        Pants.PantsTemplate = "http://www.roblox.com/asset/?id=584017819" --Changes to selected Pants.

    end

end)
Ad

Answer this question