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 8 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
8 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.

local deb = true -- set up a debounce 
local part = script.Parent -- set a variable for our part being touched

part.Touched:connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") ~= nil and deb then -- if humanoid exists and deb == true, proceed on-wards

    deb = false

    local head = hit.Parent:FindFirstChild("Head") -- finds the head

    for i,v in pairs (head:GetChildren()) do -- searches children of 'Head'
        if v:IsA("Decal") then
            v:remove() -- removes 'face' if a decal is detected
        else
            print("Not a valid decal instance")
        end
    end

        else
            print("Part is not a child of a character") 
    end

    wait(1)
    deb = true
end)

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 — 8y
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 — 8y
0
I saw one error with the script :P User#11440 120 — 8y
0
Refurbished code, there are no more errors. Ryukiyo 65 — 8y
Ad

Answer this question