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

Face decal copy block script not functioning?

Asked by 4 years ago
Edited 4 years ago

I have a script that when you touch a block named something, it puts the decal of the touched block on your face of the player.

The script goes in the serverscriptstorage but doesn't seem to work.

I got help the other day on getting where I am now and I appreciate those efforts, but if anyone could help getting this script operational that would be great!

Any feedback is great and thank you in advance!

Maybe I should switch the order of the functions?

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)



0
Update: switching order did not resolve issue 2sail2you 4 — 4y

1 answer

Log in to vote
0
Answered by
JPT79 92
4 years ago

Delete the head's current decal, then clone the new one and parent it to the head instead Something like this

if face.Texture ~= getDecal().Texture then
    face:Destroy()
    local clone = getDecal():Clone()
    clone.Parent = head
    clone.Name = "face"
end 

I'm no scripting expert myself, but I assume this should work

Ad

Answer this question