Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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.

Ad
Log in to vote
0
Answered by 7 years ago
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)

Answer this question