Hello, I need some help. I'm trying to make a face changing GUI where, when the player clicks the Image Button in the GUI, their avatar's face will change to match the image they clicked.
This is what I got so far:
function applyFace(plr) local h = plr.Character:findFirstChild("Head") if h~=nil then h.face.Texture = script.Parent.Image end end script.Parent.MouseButton1Click:Connect(applyFace)
For some reason, when I click on the face button, the output windows says "attempt to index nil with Character". Any idea on how to fix it?
I think it's due to the parameter plr
is nil. Just make a variable of player. Here's the script:
function applyFace() local plr = game.Players.LocalPlayer local h = plr.Character:WaitForChild("Head") if h ~= nil then h.face.Texture = script.Parent.Image end end script.Parent.MouseButton1Click:Connect(applyFace)
Make sure to add on line 2 or plr.CharacterAdded:Wait()
Here is an example
function applyFace(plr) local h = plr.Character:findFirstChild("Head") or plr.CharacterAdded:Wait() if h~=nil then h.face.Texture = script.Parent.Image end end script.Parent.MouseButton1Click:Connect(applyFace)
Also check if you put your script as a local script in a StarterGui