Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I remove a player's face?

Asked by 9 years ago

I was wondering how I would script a button that removes a player's face when it's touched. I know how to do the onTouched part, but whenever I try to go into the player with the get humanoid way, it says "Head is not a valid member of Player". Help? This is for a morph btw

1 answer

Log in to vote
3
Answered by
Ryukiyo 65
9 years ago

In order to remove the face of a player's character, we'll have check if the part touching the button is a child of a player. We should also check to see if the part has a humanoid (which was good for you to use in the first place, however you likely messed up on the conditional statement).

EDIT: I went ahead and re-coded this script to be more efficient when locating a face, as my last code error'ed after the face was removed from the player's character.

01local deb = true -- set up a debounce
02local part = script.Parent -- set a variable for our part being touched
03 
04part.Touched:connect(function(hit)
05    if hit.Parent:findFirstChild("Humanoid") ~= nil and deb then -- if humanoid exists and deb == true, proceed on-wards
06 
07    deb = false
08 
09    local head = hit.Parent:FindFirstChild("Head") -- finds the head
10 
11    for i,v in pairs (head:GetChildren()) do -- searches children of 'Head'
12        if v:IsA("Decal") then
13            v:remove() -- removes 'face' if a decal is detected
14        else
15            print("Not a valid decal instance")
View all 25 lines...

Questions / comments? Feel free to message me and I'll answer them as soon as possible. If you are satisfied with the answer I provided, please upvote me. Thanks!

0
I see two errors in this script. On line 5 you need to get the parent of the part first before finding the head. You would also need a capital F in FindFirstChild. But overall it's an okay answer :P User#11440 120 — 9y
0
Oh right, forgot to get the parent of 'hit'. Also, it doesn't really matter if you capitalize the :findFirstChild() function as it will work regardless. Thanks for the notifications though! Ryukiyo 65 — 9y
0
I saw one error with the script :P User#11440 120 — 9y
0
Refurbished code, there are no more errors. Ryukiyo 65 — 9y
Ad

Answer this question