Hello! I am trying to use this script that gives players a shirt/pants/hat/and random skin colors based on their team. The reason for this is it’s a war game, one team is the Peoples Army of Vietnam and the other is the Americans. I need this to work so people aren’t loading into a realism game with a neon pink skin color and random outfits.
The issue I am having is sort of odd. Half of the players that load in, load in properly. Then 1-2 players might load in with the correct outfit/hat but they’re loading in with the skin color they’ve chosen outside of the game. Then some people are loading in with the entire outfit they’ve chosen outside the game.
My problem with finding solutions, is my scripting skills are extremely weak. I have tried altering lots of code and I still can’t find a fix. I’ve changed the humanoid, humanoiddesc and wait times… Etc…
Any help would be greatly appreciated and here is my provided code!
local Teams = game:GetService("Teams")
--local Lightskin = Color3.fromRGB(204, 142, 105)
--local Darkskin = Color3.fromRGB(150, 103, 102)
--local Whiteskin = Color3.fromRGB(255, 211, 164)
local Debris = game:GetService("Debris")
local RayParams = RaycastParams.new()
game.Players.PlayerAdded:Connect(function(player)
if player.Team == Teams["USA"] then
player.CharacterAdded:Connect(function(character)
local Body_Colors = game.ServerStorage:WaitForChild("American BodyColors Folder")
local Accesories_Folder = game.ServerStorage:WaitForChild("American Accesories Folder")
local items = Body_Colors:GetChildren()
local randomItem = items[math.random(1, #items)]
Debris:AddItem(character:WaitForChild("Body Colors", 1), 0.1)
randomItem:Clone()
randomItem.Parent = character
local Humanoid = character:WaitForChild("Humanoid", 0.5)
local HumanDes = Humanoid:WaitForChild("HumanoidDescription", 0.5)
wait(.1)
local NewDesc = HumanDes:Clone()
NewDesc.Parent = nil
NewDesc.Pants = Accesories_Folder.ShirtID.Value
NewDesc.Shirt = Accesories_Folder.PantsID.Value
NewDesc.HeadColor = randomItem.HeadColor3
NewDesc.LeftArmColor = randomItem.LeftArmColor3
NewDesc.LeftLegColor = randomItem.LeftLegColor3
NewDesc.RightArmColor = randomItem.RightArmColor3
NewDesc.RightLegColor = randomItem.RightLegColor3
NewDesc.TorsoColor = randomItem.TorsoColor3
local Helmet = Accesories_Folder:WaitForChild("HelmetA"):Clone()
local Folder = Instance.new("Folder", character)
local Weld = Instance.new("Weld", Helmet)
local Head = character:WaitForChild("Head")
local Attach = Head:WaitForChild("FaceCenterAttachment")
Weld.Part0 = Helmet
Weld.Part1 = Head
Helmet.Parent = Folder
RayParams.FilterDescendantsInstances = {character.Parent, Helmet}
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
local origin = Head:WaitForChild("FaceFrontAttachment").CFrame.Position
local direction = (Head:WaitForChild("FaceFrontAttachment").CFrame.LookVector - origin).Unit * 2
local LookAt = workspace:Raycast(origin, direction, RayParams)
if LookAt then
else
LookAt = {}
LookAt.Position = origin + direction
end
Helmet.Size = Vector3.new(1.485, 1.068, 1.723)
Weld.C1 = CFrame.lookAt(Attach.CFrame.Position, -LookAt.Position) + Vector3.new(0,0.75,-.075)---.075)
Humanoid:ApplyDescription(NewDesc)
end)
elseif player.Team == Teams["Vietnam"] then
player.CharacterAdded:Connect(function(character)
local Body_Colors = game.ServerStorage:WaitForChild("Vietnam BodyColors Folder")
local Accesories_Folder = game.ServerStorage:WaitForChild("Vietnam Accesories Folder")
local items = Body_Colors:GetChildren()
local randomItem = items[math.random(1, #items)]
Debris:AddItem(character:WaitForChild("Body Colors", 1), 0.1)
randomItem:Clone()
randomItem.Parent = character
local Humanoid = character:WaitForChild("Humanoid", 3)
local HumanDes = Humanoid:WaitForChild("HumanoidDescription", 3)
wait(.1)
local NewDesc = HumanDes:Clone()
NewDesc.Parent = nil
NewDesc.Pants = Accesories_Folder.ShirtID.Value
NewDesc.Shirt = Accesories_Folder.PantsID.Value
NewDesc.HeadColor = randomItem.HeadColor3
NewDesc.LeftArmColor = randomItem.LeftArmColor3
NewDesc.LeftLegColor = randomItem.LeftLegColor3
NewDesc.RightArmColor = randomItem.RightArmColor3
NewDesc.RightLegColor = randomItem.RightLegColor3
NewDesc.TorsoColor = randomItem.TorsoColor3
local Helmet = Accesories_Folder:WaitForChild("HelmetV"):Clone()
local Weld = Instance.new("Weld", Helmet)
local Head = character:WaitForChild("Head")
local Attach = Head:WaitForChild("FaceCenterAttachment")
Weld.Part0 = Helmet
Weld.Part1 = Head
Helmet.Parent = character
RayParams.FilterDescendantsInstances = {character.Parent, Helmet}
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
local origin = Head:WaitForChild("FaceFrontAttachment").CFrame.Position
local direction = (Head:WaitForChild("FaceFrontAttachment").CFrame.LookVector - origin).Unit * 2
local LookAt = workspace:Raycast(origin, direction, RayParams)
if LookAt then
else
LookAt = {}
LookAt.Position = origin + direction
end
Weld.C1 = CFrame.lookAt(Attach.CFrame.Position, -LookAt.Position) + Vector3.new(0,0.85,0)
Humanoid:ApplyDescription(NewDesc)
end)
end
end)