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

BackgroundTransparency and ImageTransparency not working in a loop?

Asked by
RoboFrog 400 Moderation Voter
10 years ago

Well, basically, I've got a portion of a script that isn't working, when from all I can see, should be. Here's the portion in question --

local hant1 = script.Parent.haunt1.ImageTransparency
local hant2 = script.Parent.haunt2.ImageTransparency
local hant1b = script.Parent.haunt1.BackgroundTransparency
local hant2b = script.Parent.haunt2.BackgroundTransparency
local red = script.Parent.red

for i = 1,10 do
    hant1  = hant1 + .1
    hant1b  = hant1b + .2
    wait(.1)
end

wait(1)

for i = 1,10 do
    hant2b  = hant2b - .2
    hant2  = hant2 - .1
    wait(.1)
end

wait(2.5)

for i = 1,10 do
    hant2  = hant2 + .1
    hant2b  = hant2b + .2
    wait(.1)
end

for i = 1, 3 do
red.BackgroundTransparency = red.BackgroundTransparency + .3
wait()
end

for i = 1, 3 do
red.BackgroundTransparency = red.BackgroundTransparency - .3
wait(.01)
end

This is in a local script, and all of it does run (guaranteed with a print). If you need any more information, please let me know, I've tried to keep this post shorter, but as a consequence, vague.

Thank you for reading, and I hope to find a solution to this strange issue.

1 answer

Log in to vote
2
Answered by
Defaultio 160
10 years ago

It looks like your loops on 29-37 should be working, but the other three wouldn't work.

This is because when you declare your hant variables at the beginning, you're actually just declaring numbers, with values of whatever the Image/Background transparency of the objects happen to be when those lines run. When you change the values of those variables, you're not actually changing the property, just the value of the variable within the script. Instead, when you want to change the property, you need to start at the instance that owns the property. So for you, hant1 = script.Parent.hant1 and then hant1.ImageTransparency = hant1.ImageTransparency + 0.1

Hope this helps!

0
Heh, I suppose there's sometimes a place where the shortcuts are too short. That makes a lot of sense though -- things are now working as they should! Thank you for the detailed solution. RoboFrog 400 — 10y
0
No prob, I remember making this exact mistake! Defaultio 160 — 10y
Ad

Answer this question