Is it possible to make a part invisblelize a player on touch then when not touch uninvisiblize the player.
01 | script.Parent.Touched:Connect( function (plr) |
02 | if plr.Parent:FindFirstChild( "Humanoid" ) then |
03 | for i, v in pairs (plr.Parent:GetChildren()) do |
04 | if v:IsA( "BasePart" ) then |
05 | v.Transparency = 1 |
06 | end |
07 | if v:IsA( "Accessory" ) then |
08 | v.Handle.Transparency = 1 |
09 | for index, value in pairs (v.Handle:GetDescendants()) do |
10 | if value:IsA( "ParticleEmitter" ) then |
11 | value.Transparency = NumberSequence.new( 1 ) |
12 | end |
13 | end |
14 | end |
15 | end |
Insert this into a part.
This code is the same as @bebokhouja2's answer but with explanations and few improvisations.
01 | script.Parent.Touched:Connect( function (hit) -- when the player touches the part |
02 | local character = (game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) ~ = nil ) and hit.Parent -- checks if hit is the player's limb |
03 | if character:FindFirstChildOfClass( "Humanoid" ) then -- checks if the character has the "Humanoid" instance; detects if it's a real alive roblox character |
04 | for i, v in pairs (character:GetDescendant()) do -- gets all of its descendants (the children of children of children of ... children of a part) |
05 | if v:IsA( "BasePart" ) then -- checks if it's a part/limb |
06 | v.Transparency = 1 -- sets the limb invisible |
07 | elseif v:IsA( "Accessory" ) then -- if it's an accessory (e.g., Hat, Backpack, etc.) |
08 | v.Handle.Transparency = 1 -- sets the accessory invisible |
09 | for index, value in pairs (v.Handle:GetDescendants()) do -- gets its descendants |
10 | if value:IsA( "ParticleEmitter" ) then -- if it's a particle |
11 | value.Transparency = NumberSequence.new( 1 ) -- sets the particle to invisible |
12 | end |
13 | end |
14 | end |
15 | end |