Ad
Log in to vote
2

How to make a part invisblelize a player??

Asked by 13 days ago

Is it possible to make a part invisblelize a player on touch then when not touch uninvisiblize the player.

0
yes, that would be possible BulletproofVast 901 — 13d
1
How would I script it anyways?? blue_bunny0fficl 38 — 13d

2 answers

Log in to vote
1
Answered by 13 days ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
script.Parent.Touched:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") then
        for i, v in pairs(plr.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 1
            end
            if v:IsA("Accessory") then
                v.Handle.Transparency = 1
                for index, value in pairs(v.Handle:GetDescendants()) do
                    if value:IsA("ParticleEmitter") then
                        value.Transparency = NumberSequence.new(1)
                    end
                end
            end
        end
        plr.Parent.Head.face.Transparency = 1
    end
end)
script.Parent.TouchEnded:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") then
        for i, v in pairs(plr.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 0
            end
            if v:IsA("Accessory") then
                v.Handle.Transparency = 0
                for index, value in pairs(v.Handle:GetDescendants()) do
                    if value:IsA("ParticleEmitter") then
                        value.Transparency = NumberSequence.new(0)
                    end
                end
            end
        end
        plr.Parent.Head.face.Transparency = 0
        plr.Parent.HumanoidRootPart.Transparency = 1
    end
end)

Insert this into a part.

0
hi,how did you unserstod what he sayd?? Gigaset39 87 — 13d
0
hi,how did you unserstod what he sayd?? Gigaset39 87 — 13d
1
It worked thanks blue_bunny0fficl 38 — 12d
Ad
Log in to vote
3
Answered by 13 days ago
Edited 13 days ago

This code is the same as @bebokhouja2's answer but with explanations and few improvisations.

script.Parent.Touched:Connect(function(hit) -- when the player touches the part
    local character = (game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) ~= nil) and hit.Parent -- checks if hit is the player's limb
    if character:FindFirstChildOfClass("Humanoid") then -- checks if the character has the "Humanoid" instance; detects if it's a real alive roblox character
        for i, v in pairs(character:GetDescendant()) do -- gets all of its descendants (the children of children of children of ... children of a part)
            if v:IsA("BasePart") then -- checks if it's a part/limb
                v.Transparency = 1 -- sets the limb invisible
            elseif v:IsA("Accessory") then -- if it's an accessory (e.g., Hat, Backpack, etc.)
                v.Handle.Transparency = 1 -- sets the accessory invisible
                for index, value in pairs(v.Handle:GetDescendants()) do -- gets its descendants
                    if value:IsA("ParticleEmitter") then -- if it's a particle
                        value.Transparency = NumberSequence.new(1) -- sets the particle to invisible
                    end
                end
            end
        end
        character.Head.face.Transparency = 1 -- sets the face invisible
    end
end)
script.Parent.TouchEnded:Connect(function(hit) -- when the player leaves the part
    local character = (game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) ~= nil) and hit.Parent -- checks if hit is the player's limb
    if character:FindFirstChildOfClass("Humanoid") then -- checks if the character has the "Humanoid" instance; detects if it's a real alive roblox character
        for i, v in pairs(character:GetDescendants()) do -- gets all of its descendants (the children of children of children of ... children of a part)
            if v:IsA("BasePart") then -- checks if it's a part/limb
                v.Transparency = 0 -- sets the limb visible again
            elseif v:IsA("Accessory") then -- if it's an accessory (e.g., Hat, Backpack, etc.)
                v.Handle.Transparency = 0 -- sets the accessory visible again
                for index, value in pairs(v.Handle:GetDescendants()) do -- gets its descendants
                    if value:IsA("ParticleEmitter") then -- if it's a particle
                        value.Transparency = NumberSequence.new(0) -- sets the particle to visible again
                    end
                end
            end
        end
        character.Head.face.Transparency = 0 -- sets the face invisible
        character.HumanoidRootPart.Transparency = 1 -- sets the rootPart to invisible otherwise the character would look glitchy and weird
    end
end)
1
Thanks for the eplanation of the script blue_bunny0fficl 38 — 12d
1
I gave the other guy the awnser, because he did the script, but thanks for the explanation. blue_bunny0fficl 38 — 12d

Answer this question