How to create a script that causes the character to fade when gui button is pressed?

I am trying to make a gui when you press a button you character fades away, but I am having trouble trying to figure out how to accomplish that. I have basic scripting knowledge on how to create a Mouse1Click function but I have no idea how to do this one.

I’ve looked around on the on here and gone to other websites to try to find the answer or if someone could help me along the way, but this is my last resource. If anyone could help me in the right direction, it would be much appreciated.

2 Likes

for i, v in pairs(char:GetChildren()) do
if v:IsA(“Part”) or v:IsA(“MeshPart”) then
v.Transparency = 1
end
end

1.loop through the players character
2. check if the child is a part or meshpart
3. set the transparency of the part to 1

1 Like

Don’t forget that this will only hide immediate children of the character. Parts packed away in accessories or welded models will not get hidden. It’s worth creating some kind of cache for transparencies so that you can reverse it later. In addition, a better solution is to check via the superclass of parts, not an inherited class, since other part types can be in the character.

for _, v in ipairs(char:GetDescendants()) do
    if v:IsA("BasePart") then
        v.Transparency = 1
    end
end

This code is on the right track for getting players to fade away though. Fading special effects require a few more touches to them: for example, moving from 0 transparency to 1 can be done through TweenService.

The idea is to iterate through the character and set the transparency of parts upon the button being clicked. If the effect needs to replicate and be visible to other clients, a remote (RemoteEvent specifically) will have to be involved.

2 Likes