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

Why do I keep getting this error in my script to make the character have the team color outfit?

So I keep getting an error that really is stumping me, how would I fix this?

error: ServerScriptService.TeamScripts.TeamChange:11: attempt to concatenate field 'TeamColor' (a userdata value)

script: (serverscriptservice)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeamChangeEvent = ReplicatedStorage:WaitForChild("TeamChangeRemoteEvent")

function OnTeamChangedEvent(Player, ColorToChange)
    Player.TeamColor = BrickColor.new(ColorToChange)
  
    Player.CharacterAppearanceLoaded:Connect(function(Character)
          for i,v in pairs(Character:GetChildren()) do
              if v:IsA("Accessory") or v:IsA("Shirt") or v:IsA("Pants") then
                  	v:Destroy()
                    game.ReplicatedStorage["Shirt" ..Player.TeamColor].Clone().Parent = Character 
            end
        end
    end)
end

TeamChangeEvent.OnServerEvent:Connect(OnTeamChangedEvent)

1 comment

0

This error is because 'Player.TeamColor' is a Color3 value...

1 answer

✓ Accepted answer

Hello, Flakezzz!

You have a simple error, Player.TeamColor is a Color3 Value, not a string/Integer you need to use Player.TeamColor.Name

And Also, Clone() is a function, so you need to use :Clone() not .Clone()

Edited Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeamChangeEvent = ReplicatedStorage:WaitForChild("TeamChangeRemoteEvent")

function OnTeamChangedEvent(Player, ColorToChange)
    Player.TeamColor = BrickColor.new(ColorToChange)

    Player.CharacterAppearanceLoaded:Connect(function(Character)
          for i,v in pairs(Character:GetChildren()) do
              if v:IsA("Accessory") or v:IsA("Shirt") or v:IsA("Pants") then
                    v:Destroy()
                    game.ReplicatedStorage["Shirt" ..Player.TeamColor.Name]:Clone().Parent = Character --Will get the shirt with the name of the Team Color (Example: ShirtBlue)
            end
        end
    end)
end

TeamChangeEvent.OnServerEvent:Connect(OnTeamChangedEvent)

Good Luck with your games

1 comment

0

Thank you!

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