Here is my code:
In this script I attempt to make a boulder that slowly goes transparent until the boulder’s transparency is equal to 1, then it resets.
Here is my issue:
After going transparent, the transparency doesn’t go to zero again.
Here is my code:
In this script I attempt to make a boulder that slowly goes transparent until the boulder’s transparency is equal to 1, then it resets.
Here is my issue:
After going transparent, the transparency doesn’t go to zero again.
You need a wait() inside the repeat until block. You also need and end at the of that line. Please indent your code to make it easier to read.
Put wait inside the repeat loop otherwise the script will be exhausted
If there is no wait inside loops like while
or repeat until
, theoretically the script will repeat the loops infinitely times within one second, therefore “killing” the script. That’s why the script will stop executing the code to avoid “death”
Does the repeat until block only last one line? Is that why you don’t put “end” at the end of the loop for repeat until loops?
As others have stated before me, you need to yield (wait()) your script for longer.
If you do not want to do so (as it could ruin maybe the smoothness or something like that) you can also use TweenService
Does the boulder start off with 0 transparency?
Yes. It does.
(3030303030303030)
Just a suggestion, but have you considered using TweenService instead of a nested loop?
How could I use TweenService to accomplish the same thing?
How about switch line 6 with line 5?
But its already at 0 transparency, so its redundant.
No, it will repeat everything between repeat
and until
UNTIL the stuff after until
is achieved.
Alright so I fixed the error, but now the boulder won’t go back to transparency 0. It stays at 1.
may we see the new script?
abcde
local ts = game:GetService("TweenService")
local boulder = script.Parent
local waitPeriod = 1 --Change this number to how long the fading transition should be in seconds.
local tween = ts:Create(boulder, TweenInfo.new(waitPeriod), {Transparency = 1})
while true do
tween:Play()
tween.Completed:Wait()
boulder.Transparency = 0
wait(1)
end
If you don’t understand anything in this script, tell me!
I edited the main post, and that contains the updated one.
A bit of a big issue, I have no idea what TweenService does or is. I could probably search it up real quick.
That won’t work as it would set the transparency to 0 after adding 0.1 and will keep the boulder at 0 transparency. Also transparency cannot go over 1 so using >
wont work either
I found your issue!
Here’s the short explanation: Instead of boulder.Transparency == 1
, use boulder.Transparency >= 1
Here’s the long explanation: Computers aren’t precise with decimal numbers. The game believed that the transparency wasn’t 1, but 1.00000000008592 or something along those lines. SInce that isn’t 1, it kept going.
You should still use TweenService over this though, it’s definitely a skill worth learning.