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

Part disappears when touched, but is not pass-throughable. What am I doing wrong?

I'm trying to make this object not collide-able after it has disappeared, but it stays collidable.

local touchedpart = script.Parent
 
function onTouch(part)
    while true do
        wait(0.3)
        local tptrans = touchedpart.Transparency
        touchedpart.Transparency = tptrans + 0.12
    end
end
 
touchedpart.Touched:connect(onTouch)

if touchedpart.Transparency == 1 then
	touchedpart.CanCollide = false
end

1 answer

✓ Accepted answer

The problem is the value is going above when, while your script is checking if it EQUALS one. Here's a fixed version of your code:

local touchedpart = script.Parent

function onTouch(part)
    while true do
        wait(0.3)
        local tptrans = touchedpart.Transparency
        touchedpart.Transparency = tptrans + 0.12
    end
end

touchedpart.Touched:connect(onTouch)

if touchedpart.Transparency >= 1 then
    touchedpart.CanCollide = false
end

It also should noted that you're only checking once for the Transparency. Here's another version of your code that should work better:

function onTouch(part)
    while true do
        wait(0.3)
        local tptrans = touchedpart.Transparency
        touchedpart.Transparency = tptrans + 0.12
	if touchedpart.Transparency >= 1 then
	    touchedpart.CanCollide = false
	end
    end
end

touchedpart.Touched:connect(onTouch)

3 comments

0

I've just tried this, i can still collide with the object.

0

There. I updated my answer.

0

Thanks, it works now :D

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