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)
you can have a script inside of ServerScriptService and do something like this:
never tested it, may have some errors
local decals = game.Workspace:GetDescendants() for i,v in pairs (decals) do if v:IsA("Decal") then -- check if the descendant is a decal if v.Parent.Name == "FaceChanger" then -- the decal's parent's name v.Touched:Connect(function(hit) -- clones the texture to the hit.Parent's face, make sure to check if their humanoid is present first end) end end end
This is what I now have in the serverscriptservice
function getDecal() local decals = game.Workspace:GetDescendants() for i,v in pairs (decals) do if v:IsA("Decal") then -- check if the descendant is a decal if v.Parent.Name == "FaceChanger" then -- the decal's parent's name v.Touched:Connect(function(hit) -- clones the texture to the hit.Parent's face, make sure to check if their humanoid is present first end) end end end end 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 script.Parent.Touched:Connect(onTouch)