local plate = script.Parent
plate.CanCollide = true
function fade(x)
for i =1,10 do
wait(2)
plate.Transparency = plate.Transparency + x
if plate.Transparency == 1 then
plate.CanCollide = false
else
plate.CanCollide = true
end
end
end
while true do
fade(0.1)
fade(-0.1)
end
Why isn't the CanCollide property changing when the transparency = 1?
1 answer
It should be >= 1 since your loop makes your part go over 1 in transparency, defaulting to the other condition
The numbers arent exactly .1, .2,.3 etc. They look more like this:
0.10000000149012 0.20000000298023 0.30000001192093 0.40000000596046 0.5 0.60000002384186 0.70000004768372 0.80000007152557 0.90000009536743 1.0000001192093
Here are the edits I made to the code: I added a wait() between the fades because i felt like it was fading back too quickly. you can change that if you'd like.
local plate = script.Parent
plate.CanCollide = true
function fade(x)
for i = 1,10 do
wait(2)
plate.Transparency = plate.Transparency + x
print(plate.Transparency)
if plate.Transparency >= 1 then
print("item CANT be collided with")
plate.CanCollide = false
else
plate.CanCollide = true
end
end
end
while true do
fade(0.1)
wait(1)
fade(-0.1)
end
6 comments
Yes, the numbers round off because they're not literally called.
literally called?
Not literally accessed. This kind of behavior can be seen if you assign something like 0.5+0.25 to a variable and printing the variable instead of literally printing the expression.
Same thing with numerical values in Roblox. Because you're adding a literal number to a non-literal number, the compiler doesn't know what exactly to show because one number is literal and the other isn't.
that's really interesting , thanks
hi, Vlym. did you get everything alright?
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
that's because its unfading at the same time
no it's not, the function will wait for the first function to be called before the other function starts
I changed the position of the wait(2) to beneath the end of the for loop and still nothing?