Tweening ImageColor3 on GUI Image not working as intended

I’m attempting to tween a healthbar color as it reduces in health, problem I’m having is that it is changing the ImageColor3 to (1300, 63724, 0), I have no clue how its getting to this point whatsoever.

What I’m trying to achieve is for ImageColor3 of healthBarColor to be +5.1 red and -5.1 green everytime the function is called.

--services
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--replicatedStorage
local healthBarEvent = ReplicatedStorage.healthBar

--variables
local dummy = game.Workspace.Part
local dummyHealthbar = dummy.healthBar
local gradient = dummyHealthbar.healthBarFrame.healthBar.UIGradient
local dummyHealth = 100
local dummyHealthDiff = 100 - dummyHealth
local gradientgoal = Vector2.new(0, 0)
local colorValue = Color3.new(0, 255, 0)
local colorDifference = Color3.new(5.1, 5.1, 0)
local healthBarColor = gradient.Parent

local function healthBar()
	dummyHealth = dummyHealth - 2
	gradientgoal = gradientgoal - Vector2.new(0.02, 0)
	colorValue = Color3.new(colorValue.R + 5.1, colorValue.G - 5.1, 0)
	local goal = {}
	local colorGoal = {}
	goal.Offset = gradientgoal
	colorGoal.ImageColor3 = colorValue
	local TweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
	local Tween = TweenService:Create(gradient, TweenInfo, goal)
	local ColorTween = TweenService:Create(healthBarColor, TweenInfo, colorGoal)
	Tween:Play()
	ColorTween:Play()
end

healthBarEvent.OnServerEvent:Connect(function()
	healthBar()
end)

So far this is all of the code for it, I’ve tried altering it in everyway I could think of but I’m still stuck so I’ve come here.

Any help is appreciated.

Color3.new expects 3 values, all of which are a number between 0 and 1. You would need to either divide each value by 255 and pass this divided number to Color3.new, or switch from Color3.new to Color3.fromRGB.

1 Like

Switching from Color3.new to Color3.fromRGB didn’t work but dividing the values by 255 and using Color3.new worked like a charm.

Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.