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

Uniform Change on Start, No Shirt, Still Changes?

Asked by 7 years ago

So what I'm trying to explain is I have this shirt and these pants, and they'll only work if the player is currently wearing something. So let's say they color their avatar as a noob or something and wear nothing. It won't work. Please help :(

wait(2)
if script.Parent.Parent.TeamColor == BrickColor.new("Bright blue") then
if workspace:FindFirstChild(script.Parent.Parent.Name):FindFirstChild("Shirt") ~= nil then
workspace:FindFirstChild(script.Parent.Parent.Name).Shirt:remove()
b = Instance.new("Shirt")
b.ShirtTemplate = ("http://www.roblox.com/asset/?id=142159396")
b.Parent = workspace:FindFirstChild(script.Parent.Parent.Name)
elseif workspace:FindFirstChild(script.Parent.Parent.Name):FindFirstChild("Torso") ~= nil then --my troublesss
b = Instance.new("Shirt")
b.ShirtTemplate = ("http://www.roblox.com/asset/?id=142159396")
b.Parent = workspace:FindFirstChild(script.Parent.Parent.Name)
end
end
wait(2)
if script.Parent.Parent.TeamColor == BrickColor.new("Bright blue") then
if workspace:FindFirstChild(script.Parent.Parent.Name):FindFirstChild("Pants") ~= nil then
workspace:FindFirstChild(script.Parent.Parent.Name).Pants:remove()
b = Instance.new("Pants")
b.PantsTemplate = ("http://www.roblox.com/asset/?id=198079364")
b.Parent = workspace:FindFirstChild(script.Parent.Parent.Name)
elseif workspace:FindFirstChild(script.Parent.Parent.Name):FindFirstChild("Pants") ~= nil then -- don't know what to put here
b = Instance.new("Pants")
b.ShirtTemplate = ("http://www.roblox.com/asset/?id=198079364")
b.Parent = workspace:FindFirstChild(script.Parent.Parent.Name)
end
end

Thanks, LukeGabrieI

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Since it is suggested that from your title this is a change at the very beginning, you could start of with this:

game.Players.PlayerAdded:connect(function(p) 
    p.CharacterAdded:connect(function(c)
        -- Script here
    end)
end)

This will automatically get you the character, instead of using workspace:FindFirstChild(script.Parent.Parent.Name)

So the script would then go

if p.TeamColor == BrickColor.new("Bright blue") then
    if c:FindFirstChild("Shirt") then
        c.Shirt:Destroy()
    end -- Just end this if statement here so you dont have to repeat yourself if there is no shirt
        b = Instance.new("Shirt")
        b.ShirtTemplate = "http://www.roblox.com/asset/?id=142159396" -- You had brackets here which were not necessary
        b.Parent = c
end

:remove() is a deprecated function which is less efficient than :Destroy(), so I replaced it.

The :FindFirstChild("Torso") ~= nil is unnecessary.

If you want to wait for the team to change first, just add wait(x) at the beginning of the second lot (x being how many seconds you want to wait, generally 2/3)

So your final script should be something like this:

game.Players.PlayerAdded:connect(function(p)
    p.CharacterAdded:connect(function(c)
        wait(2) -- Optional
        if p.TeamColor == BrickColor.new("Bright blue") then
            if c:FindFirstChild("Shirt") then
                c.Shirt:Destroy()
            end
        b = Instance.new("Shirt")
        b.ShirtTemplate = "http://www.roblox.com/asset/?id=142159396" 
        b.Parent = c
        end
    end)
end)

And hopefully that should work for you!

Ad

Answer this question