Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to make a player's Head transparent if value is in a folder?

Hi, I'm trying to make it so that if there is a Value named "HeadTransparency" inside of a folder, then it will make the Head of a player the desired transparency. The script below works, but it does not apply it to the character that I want. Can someone help me so that it works just like the Hat Transparency part, where it checks in a folder to see if there is a named value, and then apply it? If not, it ignores it?

There is a folder in the ReplicatedStorage named "Suit_Data", which contains another folder called "Ultimate Aliens", with a folder called "Ultimate Albedo" that has a folder as well called Package, where the HeadTransparency NumberValue is located.

						for _,v in pairs(suit.Hats:GetChildren()) do
							local h = Instance.new'Hat'
							h.AttachmentForward = v.AttachmentForward.Value
							h.AttachmentPos = v.AttachmentPos.Value
							h.AttachmentRight = v.AttachmentRight.Value
							h.AttachmentUp = v.AttachmentUp.Value
							
							local p = Instance.new('Part', h)
							p.Name = 'Handle'
							p.FormFactor = 'Custom'
							p.Size = v.BrickSize.Value
							p.BottomSurface = 0 
							p.TopSurface = 0
							if v:FindFirstChild'Transparency' then --- not sure how to make it like this so that the Head Transparency works like this instead of looking for a specific thing. If the value is there, apply it. If not, it is ignored?
								p.Transparency = v.Transparency.Value
							end
							
                            --set characters head transparency
                            local head = char:WaitForChild("Head")
                            local transVal = game.ReplicatedStorage.Suit_Data["Deefus Veeblepister Suits"]["Bob the Blob"].HeadTransparency.Value
                            head.Transparency = transVal    
                            head.face.Transparency = transVal
                            -----						
							
							local m = Instance.new('SpecialMesh', p)
							m.MeshId = 'http://www.roblox.com/asset/?id='..v.MeshID.Value
							m.TextureId = 'http://www.roblox.com/asset/?id='..v.TextureID.Value
							m.Scale = v.MeshSize.Value
								
							h.Parent = char
						end

3 comments

0

Stop repeating your question

0

Stop repeating your answer? Parts of the script changed.

0

@LuckyAura ah, my bad, still you haven't fixed the mistakes I pointed out, you cant debug anything until you get those under wrap

1 answer

Close but a few mistakes, first when using a function we use () with the name, for example IsA(), FindFirstChild() you aren't using ()

    for _,v in pairs(suit.Package:GetChildren()) do
        if v:IsA('CharacterMesh') then
            v:clone().Parent = char
        if v:FindFirstChild('HeadTransparency') then
            p.Transparency = v.Transparency.Value <-- here I would want it to apply the desired Transparency to the players head but not sure how to do so.
        end 
    end
end

Second with we should do v:FindFirstChild()~=nil and also if v is that name there isn't a Transparent property inside the value so we cant do Transparency.Value

    for _,v in pairs(suit.Package:GetChildren()) do
        if v:IsA('CharacterMesh') then
            v:clone().Parent = char
        if v:FindFirstChild('HeadTransparency')~=nil then
            p.Transparency = v.Value <-- here I would want it to apply the desired Transparency to the players head but not sure how to do so.
        end 
    end
end

Lastly you aren't using elseif and have an if inside an if which means the second if statement won't run unless v is a character mesh

    for _,v in pairs(suit.Package:GetChildren()) do
        if v:IsA('CharacterMesh') then
            v:clone().Parent = char
        elseif v:FindFirstChild('HeadTransparency')~=nil then
            p.Transparency = v.Value
        end 
    end

This discussion is preserved as it was. New answers, comments, and votes are closed.