Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Ontouch Transparency

What script would I use to make my character go invisible when touching a brick and visible when not touching it? I've tried a lot.

1 comment

0

Why have I got -1 likes? What's wrong with this question?

2 answers

✓ Accepted answer
local part = Workspace.Part
part.Touched:connect(function(hitPart)
	local player = Game.Players:GetPlayerFromCharacter(hitPart.Parent)
	if player then
		for index, object in pairs(player.Character:GetChildren()) do 
			if object:IsA("BasePart") then 
				object.Transparency = 1 
				if object:FindFirstChild("face") then 
					object.face.Transparency = 1 
				end 
			elseif object:IsA("Hat") and object:FindFirstChild("Handle") then 
				object.Handle.Transparency = 1 
			end
		end
	end
end)

part.TouchEnded:connect(function(hitPart)
	local player = Game.Players:GetPlayerFromCharacter(hitPart.Parent)
	if player then
		for index, object in pairs(player.Character:GetChildren()) do 
			if object:IsA("BasePart") and object.Name ~= "HumanoidRootPart" then 
				object.Transparency = 0
				if object:FindFirstChild("face") then 
					object.face.Transparency = 0
				end 
			elseif object:IsA("Hat") and object:FindFirstChild("Handle") then 
				object.Handle.Transparency = 0
			end
		end
	end
end)

script.Parent.Touched:connect(function()
for i, v in pairs (game.Players:GetPlayers()) do
v.Character.Torso.Transparency = 1
v.Character.Head.Transparency = 1
v.Character["Left Leg"].Transparency = 1
v.Character["Left Arm"].Transparency = 1
v.Character["Right Arm"].Transparency = 1
v.Character["Right Leg"].Transparency = 1
end
end)
script.Parent.StoppedTouching:connect(function()
for i, v in pairs ( game.Players:GetPlayers()) do
v.Character.Torso.Transparency = 0
v.Character.Head.Transparency = 0
v.Character["Left Leg"].Transparency = 0
v.Character["Left Arm"].Transparency = 0
v.Character["Right Arm"].Transparency = 0
v.Character["Right Leg"].Transparency = 0
end
end)

Put this script into the part you want

8 comments

0

Oops I forgot when not touching it let me add it mmk.

0

Cheers

0

Fixed it.

0

StoppedTouching is deprecated.

1

In what way it works?I am using functions that not that many use.

0

I just switched it for TouchEnded

1

This also affects all players in the game, not just the Toucher.

0

Wow

This discussion is preserved as it was. New answers, comments, and votes are closed.