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

My part isn't disappearing when it's not touched?

I'm trying to make a part disappear when it's not touched, but I'm getting confused on how to do that.

x.Touched:connect(function()
x.Transparency = 0.5
if x.Touched == true then
x.Tranparency = 1
end
end)

tell me what I should fix. Please and thanks you :)

2 answers

✓ Accepted answer

I'm going to assume you haven't defined x yet, which is what you need to do first in order for this whole thing to work:

local x = script.Parent
 -- Set variable as local, assuming this will only be used in this particular script

x.Transparency = 0.5
-- Assuming that Transparency is already set before touching

x.Touched:Connect(function() 
-- Use :Connect instead of :connect, which is deprecated (AKA do not use it)
	x.Transparency = 1
end)

Hope this helps.

x.Touched:connect(function()
	x.Transparency = 0.5
	if x.Touched == true then
		x.Tranparency = 1
	end
end)

x.Touched only runs when the part is touched, so you do not need to do 'if x.Touched == true', it is already touched. So here is the fixed version:

ALSO: You spelled 'Tranparency' wrong on one of the lines.

x.Touched:connect(function()
	x.Transparency = 1
end)

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