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.