Right now, I am trying to add a damage indicator to make it more satisfying to hit enemies in-game by using a damage indicator. The problem is that when the tween to change enemy color plays, it lags the game a lot.
I’ve tried to use different methods, like a for loop, but it had the same issue (though I much prefer how it looks, and it’s a bit less laggy)
Here is what I had.
-- Tween (more laggy, not the whole script, just the important part)
script.Parent.Parent.Humanoid.HealthChanged:Connect(function()
if db then
db = false
if script.Parent.Parent.Humanoid.Health < oldHp then
local tweeninfo = TweenInfo.new(0.1,Enum.EasingStyle.Quad,Enum.EasingDirection.In,0,true)
local property = {
HeadColor3 = Color3.fromRGB(200,0,0),
LeftArmColor3 = Color3.fromRGB(200,0,0),
RightArmColor3 = Color3.fromRGB(200,0,0),
LeftLegColor3 = Color3.fromRGB(200,0,0),
RightLegColor3 = Color3.fromRGB(200,0,0),
TorsoColor3 = Color3.fromRGB(200,0,0),
}
local tween = tws:Create(script.Parent,tweeninfo,property)
tween:Play()
wait(0.3)
end
oldHp = script.Parent.Parent.Humanoid.Health
db = true
end
end)
--for loop (less laggy, looks better, still too laggy to play though)
script.Parent.Parent.Humanoid.HealthChanged:Connect(function()
if db then
db = false
if script.Parent.Parent.Humanoid.Health < oldHp then
local r = 20 / 255
for i=1,5 do
for _, enumItem in pairs(Enum.BodyPart:GetEnumItems()) do -- I took this from a staff post on the devforum
script.Parent[enumItem.Name .. "Color3"] = Color3.new(script.Parent[enumItem.Name .. "Color3"].R + r, script.Parent[enumItem.Name .. "Color3"].G, script.Parent[enumItem.Name .. "Color3"].B)
end
wait(0.025)
end
for i=1,5 do
for _, enumItem in pairs(Enum.BodyPart:GetEnumItems()) do
script.Parent[enumItem.Name .. "Color3"] = Color3.new(script.Parent[enumItem.Name .. "Color3"].R - r, script.Parent[enumItem.Name .. "Color3"].G, script.Parent[enumItem.Name .. "Color3"].B)
end
wait(0.025)
end
wait(0.3)
end
oldHp = script.Parent.Parent.Humanoid.Health
db = true
end
end)
If you can spot an issue, please tell me! Remember, the problem is just lag, not any errors.
Anyways, thanks.