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

How do I make my model invisible on touch?

2 answers

To do that you would have to Fire an event, for this you would have to use "Touched", What you did was only defining a function, if you want the function to get called when something happens, you need to use fire an event. The way you do this is by:

local model = script.Parent.Parent
local Connected

for _, child in pairs(model:GetChildren()) do
	if child:IsA("BasePart") then
		Connected = child.Touched:Connect(function(Hit)
			child.Transparency =0
			Connected:Disconnect()
		end)
	end
end

You might have noticed that I placed a new variable there called "Connected", then I defined the variable to the Touched event, and later disconnect the variable inside the event. I do this with touched event so, if it was touched, it will just do it one time and then wait until the part get away and retouch it again, or until it get touched again by something. This way the touched event doesn't fire multiple times.

The answer is simple. You're setting the transparency to 0, which would make it opaque (visible). A transparency of 1 however, will make the part(s) invisible.

Also since you didn't provide the entirety of the script I had to change the function a bit.

local model = script.Parent.Parent

script.Parent.Touched:connect(function(hit)
	print("test3")
	for name, child in pairs(model:GetChildren()) do
		if child.IsA("BasePart") then
			child.Transparency = 1
		end
	end
	print("test4")
end)

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