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

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

Asked by 5 years ago

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)
0
This error is because 'Player.TeamColor' is a Color3 value... Leamir 3138 — 5y

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

0
Thank you! Flakezzz 4 — 5y
Ad

Answer this question