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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)
0
I've just tried this, i can still collide with the object. sketchy54 22 — 7y
0
There. I updated my answer. antonio6643 426 — 7y
0
Thanks, it works now :D sketchy54 22 — 7y
Ad

Answer this question