Hey all,
Let me just preface this by saying I'm not a Lua C Coder in general, I come from minecraft Java plugin development and just wanted to have some fun with Roblox coding.
I have the following code which is meant to randomly assign a Hat, Shirt, Pants, and Name to a player when they join. I have set PlayerAutoLoads to false in the Players settings.
It is not working and my character loads normally without any hats or shirts.
This is the code:
local Players = game:GetService("Players")
local StarterPlayer = game:GetService("StarterPlayer")
local ServerStorage = game:GetService("ServerStorage")
local humanoidDescription = game:GetService("ServerScriptService").c_scripts.NOOB
local function CharacterSetup(player)
-- GENDER
local genders = {"boy", "girl", "mixed"}
local index = math.random(1, #genders)
local finalGender = genders[index]
-- GENDER SPECIFIC
if finalGender == "boy" then
-- NAME
local boysNames =
{
"Bravo",
"Foxtrot",
"Golf",
"Kilo",
"Mike",
"Oscar",
"Papa",
"Quebec",
"Romeo",
"Tango",
"Victor",
"Whiskey"
}
local index = math.random(1, #boysNames)
if boysNames[index] then
local finalBoyName = boysNames[index]
local stringVal = player:FindFirstChild("anonName")
stringVal.Value = finalBoyName
boysNames[index] = nil
end
-- HAT
local boysHats =
{
"CharmingBlond",
"GoldenShaggy",
"MahoganySuave",
"OrangeShaggy"
}
local index = math.random(1, #boysHats)
local finalBoyHat = boysHats[index]
local hat = game.ServerStorage.c_models.hairs:FindFirstChild(finalBoyHat)
hat.Parent = player.Character
elseif finalGender == "girl" then
local girlsNames =
{
"Alpha",
"Delta",
"Juliet",
"Lima",
"November",
"Sierra",
"Zulu"
}
if girlsNames[index] then
local finalGirlName = girlsNames[index]
local stringVal = player:FindFirstChild("anonName")
stringVal.Value = finalGirlName
girlsNames[index] = nil
end
-- HAT
local girlsHats =
{
"BlackLongHair",
"BlondLongHair",
"BrownLilyHair",
}
local index = math.random(1, #girlsHats)
local finalGirlHat = girlsHats[index]
local hat = game.ServerStorage.c_models.hairs:FindFirstChild(finalGirlHat)
hat.Parent = player.Character
elseif finalGender == "mixed" then
local mixedNames =
{
"Charlie",
"Echo",
"Hotel",
"India",
"Uniform",
"X-ray",
"Yankee"
}
if mixedNames[index] then
local finalMixedName = mixedNames[index]
local stringVal = player:FindFirstChild("anonName")
stringVal.Value = finalMixedName
mixedNames[index] = nil
end
-- HAT
local allHats =
{
"CharmingBlond",
"GoldenShaggy",
"MahoganySuave",
"OrangeShaggy",
"BlackLongHair",
"BlondLongHair",
"BrownLilyHair",
}
local index = math.random(1, #allHats)
local finalAllHat = allHats[index]
local hat = game.ServerStorage.c_models.hairs:FindFirstChild(finalAllHat)
hat.Parent = player.Character
end
-- AVATAR (COLOUR)
local humanoidBuilder = Instance.new("HumanoidDescription")
humanoidBuilder.LeftArmColor = Color3.new(255, 204, 153)
humanoidBuilder.LeftArmColor = Color3.new(255, 204, 153)
humanoidBuilder.RightArmColor = Color3.new(255, 204, 153)
humanoidBuilder.Face = 144075659
local colors =
{
"d_green",
"l_blue",
"l_green",
"blue",
"brown",
"orange",
"pink",
"purple",
"white",
"yellow"
}
local index = math.random(1, #colors)
if colors[index] then
local finalColor = colors[index]
--PathToObject:FindFirstChild(table[index])
local clothFolder = game.ServerStorage.c_models.colors:FindFirstChild(finalColor)
local shirt = clothFolder:FindFirstChild("Shirt")
local pants = clothFolder:FindFirstChild("Pants")
shirt.Parent = player.Character
pants.Parent = player.Character
colors[index] = nil
end
player:LoadCharacterWithHumanoidDescription(humanoidBuilder)
end
Players.PlayerAdded:Connect(function(player) -- Player added
--player:LoadCharacterWithHumanoidDescription(humanoidDescription)
local anonName = Instance.new("StringValue") -- MOVE TO GAMEHANDLER (ADD DESTORY OPTION)
anonName.Name = "anonName"
anonName.Parent = player
CharacterSetup(player)
end)
Its a lot I know and if your still here I appreciate it , Here are some screen shots of the explorer:
https://gyazo.com/14748c2a10e55dd0a98784b67b3e2ccc
https://gyazo.com/4ff6327e8e9294e99ce8ef163045a842
Once again I honestly thank you for your help in trying to nail this problem, I appreciate it :)

2 comments
Any errors?
Nope