Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not changing parents transparency?

Asked by 4 years ago

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
0
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. GeneratedScript 740 — 4y
0
ok Sadwowow21 57 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question