Hello!
I’m working on character customization for my game and I’ve run into a problem that I believe has something to do with players when they choose a beard. I have a print that prints the key and value within the loop. This prints four times which I assume is the problem. There are no errors, but it just stops the script and prevents it from going any further. Whether or not you choose a beard or not, nothing happens which is why I’m here. I’ve written out this code below. If you find my mistake, please let me know what I did wrong and how I can prevent it from happening again if you have questions feel free to comment .
clientServer.OnServerEvent:Connect(function(plr, msg, selectedItems, colors)
local rawData = dataModule.pullDecoded(plr, dataModule.grabFolder(plr))
local id = plr.masterFolder.basicData.selectedSlot.Value
if msg == "submit" then
serverClient:FireClient(plr, "fadeAndNext")
rawData.charData.info.hair = selectedItems["hair"]
rawData.charData.info.beard = selectedItems["beard"]
rawData.charData.info.face = selectedItems["face"]
rawData.charData.info.skin = selectedItems["skintone"]
for key,val in pairs(selectedItems) do
local find = items:FindFirstChild(key)
for key, item in pairs(selectedItems) do
print(key .. ", ".. val)
if tostring(find) == "hair" then
local hair = find:FindFirstChild(colors.hairColor):FindFirstChild(val):Clone()
local weld = Instance.new("WeldConstraint", plr.Character.Head)
weld.Part0 = plr.Character.Head
weld.Part1 = hair
hair.CFrame = plr.Character.Head.CFrame
hair.Parent = plr.Character.accessories
hair.Transparency = 0
elseif tostring(find) == "beard" then
if selectedItems.beard.Value ~= nil then
local beard = find:FindFirstChild(colors.beardColor):FindFirstChild(val):Clone()
local weld = Instance.new("WeldConstraint", plr.Character.Head)
weld.Part0 = plr.Character.Head
weld.Part1 = beard
beard.CFrame = plr.Character.Head.CFrame
beard.Parent = plr.Character.accessories
elseif tostring(find) == "face" then
local face = plr.Character.Head.face
local new = find:FindFirstChild(val.id)
print(face.Texture)
elseif tostring(find) == "skintone" then
local tone = find:FindFirstChild(val)
for _,v in pairs(plr.Character:GetChildren()) do
if v.ClassName == "Part" then
v.BrickColor = tone.Value
end
end
end
end
end
end
local newData = dataModule.EncodeUpdatedRaw(rawData)
dataModule.pushSave(plr, newData, "file".. id)
end
end)