So I asked the same question a couple of days ago, and I got an answer. However, that answer didn't work, but I am going to post the script that I was given to see if anyone can find something wrong with it.
So what the script is supposed to do is remove your clothes and give you new ones provided by the game. It is supposed to only do that if you are on a specific team. The script doesn't do anything. Can someone please help me? Here's the script:
local t2shirt = game.ServerStorage:WaitForChild("DF1") local t2pants = game.ServerStorage:WaitForChild("DF2") game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(char) if p.TeamColor == BrickColor.new("Bright blue") then if char:FindFirstChild("Pants") then char.Pants:remove() end if char:FindFirstChild("Shirt") then char.Shirt:remove() end if char:FindFirstChild("Shirt Graphic") then char["Shirt Graphic"]:remove() end t2shirt:clone().Parent = char t2pants:clone().Parent = char end end) end)
As mentioned by Shawn, BrickColor.new()
takes a string for an argument.
You can either compare the brick colors directly,
brickcolor1 == brickcolor2
use the actual name,
brickcolor1 == BrickColor.new("Really red")
or convert brickcolor2 to a string value.
brickcolor1 == BrickColor.new(tostring(brickcolor2))
Another problem is that you're calling FindFirstChild()
wrong. The syntax should be like this,
parent:FindFirstChild("childname")
However, you're doing it like this, which is incorrect.
parent:FindFirstChild()("childname")
As you can see, too many parentheses.
It is also a bad idea to store things in Lighting; although it still works, Roblox now supplies ServerStorage and ReplicatedStorage services that can be used to store objects. Using these services are more efficient than Lighting.
EDIT: The problem is the code runs before the shirts are loaded, and therefore the if statements will be false and not run. Just wait a small amount of time before checking if the shirt exists. 0.1 seconds works fine for me, but I would wait 0.5 seconds just to be safe. I have tested this and it works.
p.CharacterAdded:connect(function(char) wait(0.5)
I think the reason you script wasn't working is that you weren't waiting for the character to be fully loaded before trying to remove the pants, shirt and shirtgraphic.
local t2shirt = game.ServerStorage:WaitForChild("DF1") local t2pants = game.ServerStorage:WaitForChild("DF2") game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(char) if p.TeamColor == BrickColor.new("Bright blue") then delay(0,function() char:WaitForChild("Pants") char.Pants:Destroy() end) delay(0,function() char:WaitForChild("Shirt") char.Shirt:Destroy() end) delay(0,function() char:WaitForChild("Shirt Graphic") char["Shirt Graphic"]:Destroy() end) t2shirt:clone().Parent = char t2pants:clone().Parent = char end end) end)