I do not consider myself to be the best at Roblox scripting, but there are some mistakes that you must avoid.
- The variable
yesdoesn’t give much context or information to us when we read your code. What does this variable do? Is it important? Why is it there? Through reading your whole code thoroughly, it seems like this variable acts as a debounce. I recommend renaming this variable as debounce for better context. You can read more about debounce here. - This is really an inefficient way to “animate” your part to become transparent. Instead of using while loops, why not use TweenService? This service allows you to “animate” instances’ properties with only just a few functions and information to input.
- As mentioned by @9pwnr, you should use
task.wati()in favor ofwait()to avoid throttling. - Your
ifcontrol structure is not indented correctly. Starting from theFadingPart.Transparency = 0code line, it is not indented. This can significantly reduce readability.
No. You need to be careful on when you should use RunService.RenderStepped. As outlined by Creator Hub itself, it should only be used when dealing with the player’s character or camera.
Hope my advices help.
