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

Why doesn't this script have any effect in testing?

Asked by
Hypgnosis 186
5 years ago
Edited 5 years ago

I'm trying to script a part that endlessly fades in and out, slowly changing from 0 Transparency to 1 Transparency, then back to 0, and so on.

Below is what I've come up with, but there is no effect on the part when I run or play. No errors show in the output.

cubeTransparency = game.Workspace.Cube.Transparency

while true do
    for i = 0,1,0.1 do
        cubeTransparency = i
        wait(0.2)
    end
    wait(0.01)
end

Any help or advice would be greatly appreciated!

1 answer

Log in to vote
1
Answered by 5 years ago

Why doesn't your transparency change?

Your transparency doesn't change because the variable holds the current transparency. It doesn't effect the Part's transparency. It would only override the variable.

-- Add a local so you won't pollute the global scope
-- Let's say the Cube's transparency is 0
local cubeTransparency = game.Workspace.Cube.Transparency
-- Only overrides the variable. It wouldn't effect the actual transparency.
cubeTransparency = 1

print(game.Workspace.Cube) --> 0
print(cubeTransparency) -->1

Solution

Here is the final code.

local Cube = game.Workspace.Cube

while true do
   for Transparency = 0,1,0.1 do
      Cube.Transparency = Transparency
      wait(0.2)
   end
   wait(0.01)
end
0
Thanks! Hypgnosis 186 — 5y
0
Your welcome saSlol2436 716 — 5y
Ad

Answer this question