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

Transparency fade script not working?

Asked by
Roytt 64
8 years ago

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

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

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
Ad
Log in to vote
0
Answered by 8 years ago

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

Helped? Please Upvote me!

Answer this question