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

How do I make my face decal change?

Asked by 3 years ago
Edited 3 years ago

I was making an infection game (and infection pack) and I try to use this script:

local part = script.Parent
local faceLink = "rbxasset://20418518"

local function onPartTouched(otherPart)
    -- Get the other part's parent
    local partParent = otherPart.Parent
    -- Look for a humanoid in the parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        -- Do something to the humanoid, like set its health to 0
        partParent.Head.Face[0]:Destroy()
        partParent.Head.Face.Texture = faceLink
    end
end

part.Touched:Connect(onPartTouched)

and it does not work! How do I make the face change?

0
Hey! Thanks for the reply. I have noticed that if the part touches with other part, it will send an error that Head is not a valid member of Part. I have fixed the script for you. Also sorry for posting this comment here, the purpose is to let you get the notification. Xapelize 2658 — 3y
0
Hmm, Still won't work, I recorded footage at (shortened link) https://rb.gy/rloplj Mar10JoshIsCool 5 — 3y

1 answer

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You destroyed the face before you change the face texture. Your script should be like this:

local part = script.Parent
local faceLink = "rbxasset://20418518"

local function onPartTouched(otherPart)
    -- Detect if there is humanoid, I did a mistake in here, the reason of detecting humanoid is because detect if it's a valid character
    if otherPart.Parent:FindFirstChild("Humanoid") then
        -- Get the other part's parent
        local partParent = otherPart.Parent
        -- Set the face to faceLink
        partParent.Head.Face.Texture = faceLink
    end
end

part.Touched:Connect(onPartTouched)
0
@Xapelize Your script doesn't work for some reason... Mar10JoshIsCool 5 — 3y
Ad

Answer this question