function onTouched(part)
local character = part.Parent
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(part.Parent)
local shirt = character:FindFirstChildOfClass("Shirt")
local pants = character:FindFirstChildOfClass("Pants")
if player then
if not shirt then
shirt = Instance.new("Shirt", character)
end
if not pants then
pants = Instance.new("Pants", character)
end
if player.Team == "Red" then
shirt.ShirtTemplate = "rbxassetid://136056214"
pants.PantsTemplate = "rbxassetid://136056214"
end
if player.Team == "Blue" then
shirt.ShirtTemplate = "rbxassetid://136056667"
pants.PantsTemplate = "rbxassetid://136056667"
end
end
end
script.Parent.Touched:Connect(onTouched)
Why won't my code work? won't get past if player then.
1 answer
The Team property returns an object value (the Team in game.Teams). In lines 14-21 you should be doing:
if player.Team.Name == "Red" then
shirt.ShirtTemplate = "rbxassetid://136056214"
pants.PantsTemplate = "rbxassetid://136056214"
end
if player.Team.Name == "Blue" then
shirt.ShirtTemplate = "rbxassetid://136056667"
pants.PantsTemplate = "rbxassetid://136056667"
end
Therefore, your script was passing the check on the player, but it wasn't passing either of these, as you were checking if an object value was equal to a string value.
Resources:
Accept and upvote if this helps!
5 comments
Sweet, thanks, it works!
Ah shoot, I didn't realize that. I just assumed referencing the team object itself would use its name like when using print(). Oh well.
that only works with print() because of some reason i cant remember, hehe. but ur right, it does work that way with the print function
Question, It works for red, but not for blue. It gives me red's outfit on both teams.
print() works because it basically just uses the tostring() function
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
Not sure if I’m correct, but I believe it’s the “not”s in your conditional statement (if-then) that’s causing the problem. I think “not nil” wouldn’t be “true”(make the conditional statement go through), so instead put “shirt == nil” and “pants == nil” and see if it works.
I got that part from the roblox developer website, so I think it is right.
^ I see, I’ll just go double check to see if I’m wrong then and find what the problem is. Also note this script is supposed to work only when the player doesn’t have a shirt or pants.
oh
How do I fix that?
see my answer