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

Clothing script not working? NOT ANSWERED

Asked by
TrollD3 105
9 years ago

I want to have a script that gives you your team clothes when you enter the game. This is the script I have. In the Output it says Line 29 global removepants, line 40 global on PLayer Respawned, and something about line 53. It doesnt work when you spawn, and the clothing temples are the children of the script.

function removeShirt(character) 
    while character:findFirstChild("Shirt")~=nil do character.Shirt:remove() end --Removes current shirt 
end

function removePants(character) 
    while character:findFirstChild("Pants")~=nil do character.Pants:remove() end --Removes current Pants
end

function removeTShirt(character) 
    if character:findFirstChild("Torso") and character.Torso:findFirstChild("roblox") then --Removes current TShirt
        character.Torso.roblox:remove()
    end                                   --             The Functions above remove the new players clothing
end

function onPlayerRespawned(newPlayer)
            if newPlayer.TeamColor == game.Teams["Atlas"].TeamColor then --Checks to see if the player is on the team
                removePants(char)
                removeShirt(char)              --Removes clothing
                shirt3 = script.Clothing2:clone()
                shirt4 = script.Pants2:clone()
                shirt3.Parent = char       --Clones and equips the new uniform
                shirt4.Parent = char
                return
            end
            end

function onPlayerEntered(newPlayer)
        newPlayer.Changed:connect(function (property)
                if (property == "Character") then
                        onPlayerRespawned(newPlayer) -- Checks if the Player is a Character
                end
        end)

    end

game.Players.PlayerAdded:connect(onPlayerEntered)

2 answers

Log in to vote
0
Answered by 9 years ago

I have cleaned up the code and changed the event to characterAdded, also I have not tested the shit cloning part as I don't have the parts to clone.

Hope this helps:-

--Realy simple function to remove an item
function rmItm(char, itm) 
    --waits for the item just in case
    while not char:WaitForChild(itm) do wait() end
    --finds the item
    local item = char:FindFirstChild(itm)
    --removes the item
    item:remove()
end

--New player
game.Players.PlayerAdded:connect(function (plr)

    print("Player Added:- " .. plr.Name)    

    --character load
    plr.CharacterAdded:connect(function (char)

        --wait for character but clothes do not load??
        while char == nil do wait()end  
        print("Player Sporned:- " .. char.Name)

        wait(2) --dont know how to wait for all of the character to load? shirt not present with other waiting methods? 

        --lopp through all of the characters incase they have multiple hatz etc.
        for _,v in pairs(char:GetChildren()) do

            --character item v class check to see what it realy is just in case the name is wrong
            if v:IsA("Shirt") or v:IsA("Hat") or v:IsA("Pants")then
                rmItm(char, v.Name)
                print("Removed:- " .. v.Name)
            end                                 
        end

        --All done
        print("Player cleaned")

        --I dont know if this will work as i dont have the rsources to test this
        if plr.TeamColor == game.Teams["Atlas"].TeamColor then 
            shirt3 = script.Clothing2:clone()
            shirt4 = script.Pants2:clone()
            shirt3.Parent = char       --Clones and equips the new uniform
            shirt4.Parent = char
        end

    end)    

end)
Ad
Log in to vote
0
Answered by
Xulp 0
9 years ago

Well, you should be using the Player.CharacterAdded event. Your line numbers are also off so I don't know what you're referencing.

0
..... TrollD3 105 — 9y

Answer this question