Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is there a delay between the health and GUI?

Asked by 7 years ago

This is a script in a health GUI but there's a delay when the health is changed.

local Player = script.Parent.Parent.Parent.Parent
local Char = Player.Character
local Humanoid = Char:findFirstChild("Humanoid")
local HealthBar = script.Parent.HealthBar
local HealthPosition = UDim2.new(0.345,0,0.5,-10)
local HealthSize = UDim2.new(0,220,0,20)
local EnergyBar = script.Parent.EnergyBar

Humanoid.Changed:connect(function(Change)
    if Change == "Health" then
        local HP  = Humanoid.Health
        HealthBar:TweenSize(UDim2.new(0.0088*HP,0,0,20), "Out", "Quad",0.4, true) 
    end
end)


1 answer

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

This happens because you do 0.4 in your tweenSize, this is the animation time for the tween.

Set this to 0 (Or just don't use tweening at all if you dont want an animation) to get rid of the delay.

Also, suggest doing HP/MaxHP instead of 0.0088*HP for a smooth 0 to 1 ratio.

Ad

Answer this question