Hi, I have this very basic "face changer" script that you place inside of a block with a decal on it, and when you touch the decal, your face copies the decal onto it. Now I have several of these decal blocks lined up with a script in each one and wanted to create a overarching script that could substitute each script for a single one. How would I go about doing this? I would want the player to touch one of the decals and for that decal to appear on their face. There would be serval decal blocks all next to each other.
Thank you in advance! Any feedback is great!
This is the script/code for one block. I was thinking of maybe giving each block a numbervalue?
// My workspace looks like this:
//Model
//-FaceChanger
// -Decal
//-FaceChanger
// -Decal
//Maybe I do like
//Model
//-FaceChanger1
// -Decal
//-FaceChanger2
// -Decal
//If I did that, I would need to change function getDecal() but this is where I get lost
function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
local head = hit.Parent:FindFirstChild("Head")
if head ~= nil then
local face = head:FindFirstChild("face")
if face.Texture ~= getDecal().Texture then
face.Texture = getDecal().Texture
end
end
end
end
function getDecal()
local decals
decals = {}
for i,child in pairs(script.Parent:GetChildren()) do
if child.className == "Decal" then
table.insert(decals, child)
end
end
if #decals ~= 0 then
return decals[math.random(1, #decals)]
end
return nil
end
script.Parent.Touched:Connect(onTouch)

3 comments
Thank you, and I love the idea of putting it in the ServerScriptService although it didn't work. I appreciate it tho!
why didnt it work?
Take a look at what I wrote in the comments below, but basically nothing happens if I touch the part with a decal in it. Not sure what I should do