I am trying to make this change the BackgroundColor3
to one shade less than the current one, can anyone tell me how to make this script work properly?
Code:
local this = script.Parent while wait(0.03) do for a = 1, 70 do this.BackgroundColor3 = Color3.new(this.BackgroundColor3-1) wait(0.03) end end
Output:
attempt to perform arithmetic on field 'BackgroundColor3' (a userdata value)
local this = script.Parent -- for a = 1, 70 do this.BackgroundColor3 = Color3.new( this.BackgroundColor3.r - (1/255), this.BackgroundColor3.g - (1/255), this.BackgroundColor3.b - (1/255) ) wait(1/30) end
This will run the for loop once, which will reduce the GUI's BackgroundColor3 by Color3.new(70/255, 70/255, 70/255) total, over the course of ~2.3 seconds. I'm not sure exactly what you need this for, so that's the best I could do.
The main problem in your original script was the statement
this.BackgroundColor3 = Color3.new(this.BackgroundColor3-1)
Color3.new(r, g, b) takes 3 parameters ranging from 0 - 1. Also, you cannot subtract an integer (1) from a userdata value (Color3).
Color3 is kinda like Vector3. You can't subtract a number from the set itself...
this.BackgroundColor3 = Color3.new(this.BackgroundColor3-1)
but you can subtract one from each element in the set...
original = this.BackgroundColor3 this.BackgroundColor3 = Color3.new(this.r - 1, this.g - 1, this.b - 1) --r, g and b is the equivalent of x, y and z in Vector3.
However, Color3 is a bit weird. In the properties window, the values of Color3 seem to be [255, 255, 255]. However, its true value is [1, 1, 1]. Thus, [0, 0, 0] is pitch black, and [1, 1, 1] is pure white. If we subtract 1 from the Color3 values, we're immediately going from white to black. To fix this, divide by 255:
original = this.BackgroundColor3 this.BackgroundColor3 = Color3.new(original.r - 1/255, original.g - 1/255, original.b - 1/255)
Full script:
local this = script.Parent while wait() do --The default value for the wait function is set to 0.03. for a = 1, 70 do local original = this.BackgroundColor3 this.BackgroundColor3 = Color3.new(original.r - 1/255, original.g - 1/255, original.b - 1/255) wait() end end