01 | script.Parent.ClickDetector.MouseClick:connect( function () |
02 | local obj = script.Parent |
03 | local transpar = obj.Transparency |
04 | local anchr = obj.Anchored |
05 | local cancoll = obj.CanCollide |
06 |
07 |
08 | transpar = 0.1 |
09 | wait( 0.1 ) |
10 | transpar = 0.2 |
11 | wait( 0.1 ) |
12 | transpar = 0.3 |
13 | wait( 0.1 ) |
14 | transpar = 0.4 |
15 | wait( 0.1 ) |
I am attempting to make a block's transparency change over time on click. This isn't working for some reason and I am confused as to the reason why. I suspect that it is something with my function setup, but I am not sure. Please explain your answer, thank you.
Let me show you a much easier way to do this. It uses a for loop that runs until I is equal to 1 at 0.1 intervals. Also, your variables are messed up, I'm a bit confused as to what you're trying to do when you made a variable of the objects properties but try this.
1 | script.Parent.ClickDetector.MouseClick:connect( function () |
2 | for i = 0 , 1 , 0.1 do |
3 | wait( 0.1 ) |
4 | obj.Transparency = i |
5 | end |
6 | end ) |
Yoshi is correct that you should be using a for
loop, but that's not why your code wasn't changing the transparency.
On line 3, you wrote
1 | local transpar = obj.Transparency |
In other words, you made a variable equal to a property.
Don't do this.
When a variable is set to a property, it simply becomes the value of that property. It retains no reference to the actual object. transpar
is just a number.
1 | local transpar = obj.Transparency |
2 | -- equivalent to; |
3 | local transpar = 0 |
Make your variables equal to objects. Then you can edit their properties.
1 | obj.Transparency = 0.5 |