Still have questions? Join our Discord server and get real time help.
1

# Why won't my code work? won't get past if player then.

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)

0
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. Denny9876 1247 — 2mo
1
I got that part from the roblox developer website, so I think it is right. PaliKai13 65 — 2mo
0
^ 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. Denny9876 1247 — 2mo
0
oh PaliKai13 65 — 2mo
0
How do I fix that? PaliKai13 65 — 2mo
0
see my answer gioni01 2015 — 2mo

3
gioni01 2015
2 months ago
Edited 2 months ago

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:

Team

Accept and upvote if this helps!

1
Sweet, thanks, it works! PaliKai13 65 — 2mo
1
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. Denny9876 1247 — 2mo
1
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 gioni01 2015 — 2mo
1
Question, It works for red, but not for blue. It gives me red's outfit on both teams. PaliKai13 65 — 2mo
1
print() works because it basically just uses the tostring() function ihatecars100 395 — 2mo