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

How do I make Accessory transparent? [R15]

Asked by 4 years ago
Edited 4 years ago

Hi I have a script where if you touch the part you will become transparent for 5 seconds and reappear again, but for some reason accessories won't become transparent with the rest.

function setTransparency(char, value)
    for _, child in pairs(char:GetChildren()) do
        if child:IsA('Accessory') and child:FindFirstChild("Handle") then
            child = child.Handle
        elseif child:IsA('BasePart') and child.name ~= "HumanoidRootPart" then
            child.Transparency = value
        end
    end
end

local enabled = true
game.Workspace.TransPart.Touched:connect(function(hit)
    local char = hit.Parent
    if char then
        local head = char:FindFirstChild("Head")
        local face = head:FindFirstChild("face")
        if enabled and head and game.Players:GetPlayerFromCharacter(char) then
            enabled = false
            for t = 0, 1, 1 do
                if face then face.Transparency = t end
                setTransparency(char, t)
                wait(0.1)
            end
            wait(5)
            for t = 1, 0, -1 do
                if face then face.Transparency = t end
                setTransparency(char, t)
                wait(0.1)
            end
            wait(1)
            enabled = true
        end
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I might have the solution to your problem:

if child:IsA("Accessory") then
       for _, accessoryPart in pairs(child:GetChildren()) do
          if accessoryPart.ClassName == "Part" then
            accessoryPart.Transparency = value -- or whatever you define your transparency as
end

So basically, all accessories have a child called "handle" that makes the accessory's shape. So what we are doing is finding the children of the accessory and if they are a part, we are setting its transparency to 1, thus making it invisible. This is since all instances with the class name of "Part" have the transparency property. (The handle is a part.)

Try this and if it doesn't work or you need a better explanation of how it works, tell me in the comments. If this is the answer please consider marking this as the answer, so we both can get reputation points :D. I hope you have a great day!

0
Thank you so much for the answer! habloshom 9 — 4y
0
No problem :) SprinkledFruit101 135 — 4y
Ad

Answer this question