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

Why is this specific team affecting script not working?

Asked by 9 years ago

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)
0
Line 7, put the actual BrickColor for its TeamColor Shawnyg 4330 — 9y
0
(I updated my answer) Perci1 4988 — 9y

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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)
0
Does it matter that the script is a regular script type? CoolJohnnyboy 121 — 9y
0
Also, the script still does not work. CoolJohnnyboy 121 — 9y
Ad
Log in to vote
0
Answered by
samfun123 235 Moderation Voter
9 years ago

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)

Answer this question