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)
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