I'm quite new to scripting... and I'm still learning the ropes. However this is one thing for the life of me I can't do.. that seems SO SIMPLE.
I'm trying to add an add on for the players face when they touch a part, but all I have is a normal face changer. I don't want it to replace the face, only add on top of it.
```lua
local head = script.Parent
local sound = head:findFirstChild("Victory")
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
sound:play()
if part.Parent:findFirstChild("Head"):findFirstChild("face") then return end
part.Parent:findFirstChild("Head"):findFirstChild("face").Texture=script.Parent.Decal.Texture
end
end
script.Parent.Touched:connect(onTouched) ```
If you could help that'd be awesome. ^^
local head = script.Parent
local sound = head:findFirstChild("Victory")
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
sound:play()
if part.Parent.Head.face then return end
local clone = part.Parent.Head.face:Clone() --Cloning the object clone.Parent = part.Parent.Head --Making sure that the parent is "Head" clone.Texture = script.Parent.Decal.Texture --Setting the texture end
end
script.Parent.Touched:connect(onTouched)
Note: 1. Try not to use the FindFirstChild() function too much, your script might be harder to understand. 2. The Clone() function will clone an object
The :Clone()
function should do the trick. To use it, just do FaceDecal:Clone()
and be sure to set it's parent to the player's head, as by default, a clone's parent is nil
.