Lines 3 through 7 have no effect on the part. No errors show in output. The rest works exactly as I want, but I need help with the if statement.
local cube = script.Parent while true do if cube.Transparency < 0.5 then cube.CanCollide = false else cube.CanCollide = true end for i = 0,1,0.01 do cube.Transparency = i wait(0.05) end for i = 1,0,-0.01 do cube.Transparency = i wait(0.05) end wait(0.01) end
It is because scripts run from the top down, you have to include the condition checking in your for loops
The If statement only gets checked when the while loop repeats, and when the loop repeats the Cube transparency is 0 which is why CanCollide is always false if its < and true if its > in your script. Thats why your if statement must be in the for loop not the while loop
local cube = script.Parent while true do for i = 0,1,0.01 do if cube.Transparency > 0.5 then cube.CanCollide = true end cube.Transparency = i wait(0.05) end for i = 1,0,-0.01 do if cube.Transparency < 0.5 then cube.CanCollide = false end cube.Transparency = i wait(0.05) end wait(0.01) end