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

Unable to get Player's shirt, am I missing anything?

Asked by 6 years ago

Part One: Could any lads help me out? I am trying to create a tool that upon clicking it, it turns your shirt into specified clothing and once you click it again it returns your clothing to a normal state? (This is part one of what I am creating.)

Before I was stupid and didn't realise that for the script to work it had to be equipped but then, will it still work before it's equipped/placed in the backpack since those were the errors I've been getting?


(IGNORE THIS PART, THIS ONLY DESCRIBES THE PURPOSE FOR ACTIVATED) Part Two: The part two of what I am creating for the users clothing to display on the clothing hanger once they changed their outfit the specified outfit. Before they equip the outfit, the specified outfit will display on the clothing hangar instead.

https://gyazo.com/c01330b67b8f4d0d1d948b602262dbed The link provided shows how the clothing hangar and the clothing itself will look like. The clothing hangar uses humanoid appearance such as shirt and pants, this way it can display the clothes by the shirt.


The code is short since I kept changing the code multiple times and I haven't came to the solution which just got the code shorter and shorter. However this is how I understand what I've written.

Legend/Key:

  • model is basically the model that the script is in(will be used by multiple people)

  • player is the user themself

  • userShirt is the shirt that the player is wearing by the avatar

  • currentShirt is the shirt they are currently wearing

  • gameShirt is the specific shirt they will be equipped with.

  • save is a value where the user's shirt was meant to be stored which can be used again by the currentShirt to be reequipped with.

  • activated was going to be used in changing the clothing on the clothing hangar so basically if 1 display whatever etc.

while true do
    local model = script.Parent
    local player = game.Players.LocalPlayer
    local userShirt = player.Character.Shirt.WaitForChild("ShirtTemplate") -- Problem starts
    local currentShirt = player.Character.Shirt
    local gameShirt = "rbxassetid://1219882549"
    local save = model.SavedShirt
    save = userShirt
    activated = 0

    local function OnActivate()
        if activated == 1 then
            currentShirt.ShirtTemplate = gameShirt.ShirtTeplate
        elseif activated == 0 then
            currentShirt.ShirtTemplate = save.ShirtTemplate
        end
    end
end

What is the trouble I am having with?

The problem is that the code isn't able to find the shirt of the player that is being worn by the player themselves, I've tried looking for solutions online and I am out of luck, I've tried looking at the roblox wiki for properties that I could use but I am still having trouble finding the solution. From my point of view the code is useless and probably all wrong especially when this is my very first project involving scripting. I am hoping to see some help, thanks.

If you have any questions feel free to ask as I am roaming around the internet all the time.

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

Your using :WaitForChild() incorrectly, you can only use it to find instances, not their properties. Its the same thing as :FindFirstChild(), but waits until it finds the instance and sends a infinite yield error if unable to find the instance.

If your finding something from the character, you have to add a 'repeat wait() until'

repeat wait() until game.Players.LocalPlayer.Character
repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(game.workspace)
wait(1 / 20) -- always keep this on the top of the local script

while true do
    local model = script.Parent
    local player = game.Players.LocalPlayer
   -- local userShirt = player.Character.Shirt.WaitForChild("ShirtTemplate") -- WaitForChild uses : before it only, not periods
    local currentShirt = player.Character:WaitForChild('Shirt') -- waits for Shirt
    local shirtTemplate = currentShirt.ShirtTemplate -- suggest changing 'userShirt' as shirtTemplate, this finds the ShirtTemplate property of the currentShirt
    local gameShirt = "rbxassetid://1219882549"
    local save = model.SavedShirt
    save = shirtTemplate
    activated = 0

    local function OnActivate()
        if activated == 1 then
          -- shirtTemplate = gameShirt.ShirtTemplate -- gameShirt, is a ID, it has no property 'ShirtTemplate'
        shirtTemplate = gameShirt
        elseif activated == 0 then
            shirtTemplate = save.ShirtTemplate
        end
    end
end
Ad

Answer this question