Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my team change script not change clothes?

I have a simple team change script that also changes the clothes but always changes the clothes to the terrorist side clothes, any help is appreciated.

Video: https://streamable.com/b3al2c

Explorer: https://imgur.com/a/Ltseznk

Code:

local TC = Instance.new("RemoteEvent")
TC.Name = "TeamChanger"
TC.Parent = game.ReplicatedStorage
local teams = game.Teams

TC.OnServerEvent:Connect(function(Player, TeamName)
	Player.Team = game.Teams[TeamName]
	Player:LoadCharacter()
	char = Player.Character


	if Player.Team == "Counter Terrorists" then
		if char:FindFirstChild("Shirt") then
			char.Shirt:Destroy()
		end
		
		if char:FindFirstChild("Pants") then
			char.Pants:Destroy()
		end
		
		local shirt = teams["Counter Terrorists"].Shirt:Clone()
		shirt.Parent = char
		local pants = teams["Counter Terrorists"].Pants:Clone()
		pants.Parent = char
	else
		if char:FindFirstChild("Shirt") then
			char.Shirt:Destroy()
		end

		if char:FindFirstChild("Pants") then
			char.Pants:Destroy()
		end

		local shirt = teams["Terrorists"].Shirt:Clone()
		shirt.Parent = char
		local pants = teams["Terrorists"].Pants:Clone()
		pants.Parent = char
		
	end
end)

1 comment

0

Line 12 should either check if the player's team name is equal to "Counter Terrorists" or if the player's team is equal to the actual team object (ie game.Teams["Counter Terrorists"]. Right now, you're asking if the team object is equal to a string.

1 answer

✓ Accepted answer

As explained in my comment...

local TC = Instance.new("RemoteEvent")
TC.Name = "TeamChanger"
TC.Parent = game.ReplicatedStorage
local teams = game.Teams

TC.OnServerEvent:Connect(function(Player, TeamName)
    Player.Team = game.Teams[TeamName]
    Player:LoadCharacter()
    char = Player.Character


    if Player.Team.Name == "Counter Terrorists" then
        if char:FindFirstChild("Shirt") then
            char.Shirt:Destroy()
        end

        if char:FindFirstChild("Pants") then
            char.Pants:Destroy()
        end

        local shirt = teams["Counter Terrorists"].Shirt:Clone()
        shirt.Parent = char
        local pants = teams["Counter Terrorists"].Pants:Clone()
        pants.Parent = char
    else
        if char:FindFirstChild("Shirt") then
            char.Shirt:Destroy()
        end

        if char:FindFirstChild("Pants") then
            char.Pants:Destroy()
        end

        local shirt = teams["Terrorists"].Shirt:Clone()
        shirt.Parent = char
        local pants = teams["Terrorists"].Pants:Clone()
        pants.Parent = char

    end
end)

2 comments

1

Thanks a lot! i think you just saved me from 5 years of searching stuff on the internet!

0

You're welcome. Upvote if it helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.