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

Why can I add, but not subtract?

So I'm working with a point light, and I'm trying to get a glowing effect that gradually changes from one color to another.

light = script.Parent;
r =0-- math.random (0,255)
g = 0--math.random (0,255)
b = 255--math.random (0,255)
colors = {r,g,b}

function UpdateColor ()
	light.Color = Color3.new (r/255,g/255,b/255)
	wait (.1)
end

while wait () do
	print 'stage 1'
		for i = 0,50-r do
			if r < 255 then
				r = r + 5;
				UpdateColor () -- fades to purple, this is where the color is 255,0,255
			else r = 0;
				UpdateColor ()
			end
		end
	print 'stage 2'
		for i = 0,50-b do -- 50 is one less than 255/5.
			if b > 0 then
				b = b - 5; -- this is why I divide it by 5
				UpdateColor () -- fades to red, this doesn't work! Right now the color is still 255,0,255
			else b = 255;
				UpdateColor ()
			end
		end

Any and all help will be appreciated.

2 answers

✓ Accepted answer

You can, the problem is that the statement is not being executed because of

for i = 0,50-b do 

Since b = 255, 50 - 255 is -205, so for 0,-205 is not going to execute because the default step is 1

1 comment

0

Thanks. It's fixed! I'm really prone to making dumb mistakes like that, haha!

It is going to -205 because the variable b = 255...........

1 comment

0

So when you do for = 1,50-b it goes to -205

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