Color3:Lerp is not working as intended

Heya.

I’ve cooked up a script where whenever its text changes, the color of the text and its Parent’s ImageColor3 also changes its color.

script.Parent.Changed:Connect(function()
	if script.Parent.Text == 0 then
		script.Parent.Parent.ImageColor3 = script.Parent.Parent.ImageColor3:Lerp(Color3.fromRGB(255,255,255),0.5)
		script.Parent.TextColor3 = script.Parent.TextColor3:Lerp(Color3.fromRGB(255,255,255),0.5)
		script.Parent.TextStrokeColor3 = script.Parent.TextStrokeColor3:Lerp(Color3.fromRGB(102, 102, 102),0.5)
	elseif script.Parent.Text == 1 then
		script.Parent.Parent.ImageColor3 = script.Parent.Parent.ImageColor3:Lerp(Color3.fromRGB(188, 253, 185),0.5)
		script.Parent.TextColor3 = script.Parent.TextColor3:Lerp(Color3.fromRGB(188, 253, 185),0.5)
		script.Parent.TextStrokeColor3 = script.Parent.TextStrokeColor3:Lerp(Color3.fromRGB(83, 110, 82),0.5)
    end
end)

When testing this out, I do not get any results. I have tried this on both a server script and a local script and none have worked.

I know this is probably impractical and there’s probably a better way to do this.

Make sure to change your script.Parent.Text == 0 and script.Parent.Text == 1 to surround quotation marks around the 0 and 1, that is why you’re not getting any results.

2 Likes

I keep learning more stuff everyday. Thanks so much!

Not related to your question but you can also assign the script.Parent to a variable so you don’t have to write script.Parent everytime like this:

local object = script.Parent --You can change the "object" variable to anything else you want. I just named it object for this example.

By looking at your code I think you’re trying to run your code when the Text property changes which in this case you can use :GetPropertyChangedSignal() instead of .Changed event like this so function only runs when text changes like this:

local object = script.Parent
object:GetPropertyChangedSignal("Text"):Connect(function()
if object.Text == "0" then
object.Parent.ImageColor3 = object.Parent.ImageColor3:lerp(Color3.fromRGB(255,255,255),0.5)
object.TextColor3 = object.TextColor3:Lerp(Color3.fromRGB(255,255,255),0.5)
object.TextStrokeColor3 = object.TextStrokeColor3:Lerp(Color3.fromRGB(102, 102, 102),0.5)
elseif object.Text == "1" then
object.Parent.ImageColor3 = object.Parent.ImageColor3:Lerp(Color3.fromRGB(188, 253, 185),0.5)
object.TextColor3 = object.TextColor3:Lerp(Color3.fromRGB(188, 253, 185),0.5)
object.TextStrokeColor3 = object.TextStrokeColor3:Lerp(Color3.fromRGB(83, 110, 82),0.5)
end
end)

You can also assign the object.Parent like local object2 = object.Parent to a variable which would make it better but I just gave this code as an example on how to make the code run a bit more efficient and look better.

1 Like