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

Transparency fade script not working?

I want to make two parts to have a fade effect when a condition is met but it's not working

local one = script.Parent.Part1
local two = script.Parent.Part2
local c1 = 150

if script.Parent.Nexus.Value.Value == "true" then
	for i=0, c1 do
		one.Transparency = one.Transparency - 0.05
		two.Transparency = two.Transparency - 0.05
		wait()
	end
	for i =0, c1 do
		one.Transparency = one.Transparency + 0.05
		two.Transparency = two.Transparency + 0.05
		wait()
	end
wait()	
end

2 answers

✓ Accepted answer

If statements only check something once. You code will check the condition at the beginning of the game and never again.

You need to use an event. An event will do something when the 'event' happens. In this case you want to do something when the value is Changed.

value.Changed:connect(function(val)

end)

Moreover, assuming your value is a BoolValue, you cannot check it by comparing it to "true", for that is merely a collection of characters, not a boolean value. "true" is totally different than true.

if value == true then

Finally, although this wouldn't prevent your code form working, you might as well use the built in for loop variable for the transparency change.

for i = 0, 1, 0.01 do
	part.Transparency = i
end

unless Nexus is a string value, make sure true is not in quotes. Also, you have Value twice after Nexus.

Helped? Please Upvote me!

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