Quick question with scripting

I am taking a roblox dev hub tutorial and it says that this code here will make it fade,
though the part when it says platform.transparency = count / 10 I don’t really know why they put count / 10, can you guys explain this to me?

local platform = script.Parent

function fade()
for count = 1,10,1 do
platform.Transparency = count / 10
wait(0.1)
end

end
platform.touched:Connect(fade)

1 Like

Transparency goes from 0-1. Now this loop will loop ten times, and each time count will get 1 greater each time, starting at I and ending at 10. Because transparency cannot go above 1 they divide it by ten each time so that you get a number that starts at 0.1 and ends at 1.

First loop: count is 1 so transparency is 0.1,
Second loop: count is 2 so transparency is 0.2,
Third loop: count is 3 so transparency is 0.3
--etc..
2 Likes

It’s basically working like this

The code loops from 1 to 10

The transparency is set to the current iteration divided by 10, so if it’s on the 2nd loop, it will do 2 /10, which is 0.2, since transparency goes from 0-1, where 0 is visible and 1 is invisible

2 Likes

oh ok! thanks guys, this is gonna be really helpful :smiley:

2 Likes

I think you made a mistake here since Transparency goes from 0 - 1

2 Likes

oh yeah that is true but its fine :slight_smile:

Thank you that simple typo could cause a lot of confusion. I just fixed it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.