Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

##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

2 comments

0

Thanks!

0

Your welcome

This discussion is preserved as it was. New answers, comments, and votes are closed.