I was messing around with a script, and I was trying to randomly change the transparency of a part but it isn't working. Here is the code:
while true do
script.Parent.Transparency = math.random(-0.5, 0.5)
wait(1)
end
I was messing around with a script, and I was trying to randomly change the transparency of a part but it isn't working. Here is the code:
while true do
script.Parent.Transparency = math.random(-0.5, 0.5)
wait(1)
end
You're problem is that Transparency can not be a negative number. Change your math.random() to math.random(0, 1). 0 means that the part is completely opaque while 1 would be invisible. Also, do not listen to GeneratedScript with the while wait(1) do, it is seen as bad practice and what you have now is considered better. Just to be clear, your script will make one simple change to look like this:
while true do
script.Parent.Transparency = math.random(0, 1)
wait(1)
end
The only other way that this script could not work is if you don't have the script's parent as the part. I hope I helped!
EDIT: Transparency is also very hard to see with numbers lower than .5 (for me at least). You may want to consider printing the transparency value after every time the while true do statement runs to make sure that the value is in fact changing.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Ok so, firstly, delete the wait(1) and add it to the while loop. 'while wait(1) do'. Then, try pcalling it to see what's up.
ok