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

Why isn't the CanCollide property changing when the transparency = 1?

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

3 comments

0

that's because its unfading at the same time

0

no it's not, the function will wait for the first function to be called before the other function starts

0

I changed the position of the wait(2) to beneath the end of the for loop and still nothing?

1 answer

✓ Accepted 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

0

Yes, the numbers round off because they're not literally called.

0

literally called?

1

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.

0

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.

0

that's really interesting , thanks

0

hi, Vlym. did you get everything alright?

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