Hi! So i recently begun adding more Roact components into my game. And i have made a health bar it works perfectly but its the fact it doesn’t Lerp none of the documentation showed Lerp but every event works. How would i make the actual bar Lerp with it while still using Roact.
Anyways Here is my code below: How would i implement Lerping thanks!
Anyways Heres my code
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Roact = require(ReplicatedStorage.Modules.Roact)
local HealthBar = Roact.Component:extend('HealthBar')
local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Health = Humanoid.Health
function HealthBar:init()
self:setState({
health = 0,
maxHealth = 0,
})
end
function HealthBar:didMount()
local function updateHealth(health)
self:setState({health = health})
print(health)
end
local function handleCharacter(character)
self.healthChangedConnection = Humanoid.HealthChanged:Connect(updateHealth)
self.maxHealthChangedConnection = Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
self:setState({maxHealth = Humanoid.MaxHealth})
end)
self:setState({
health = Humanoid.Health,
maxHealth = Humanoid.MaxHealth,
})
end
handleCharacter(Character)
end
function HealthBar:render()
return Roact.createElement('ScreenGui', nil, {
HealthBarFrame = Roact.createElement('Frame', {
BorderSizePixel = 0,
Size = UDim2.new(0.35, 0,0.05, 0),
Position = UDim2.new(0.011, 0,0.938, 0),
BackgroundColor3 = Color3.fromRGB(47, 255, 32),
})
})
end
function HealthBar:willUnmount()
self.characterAddedConnection:Disconnect()
local healthChangedConnection = self.healthChangedConnection
if healthChangedConnection then
healthChangedConnection:Disconnect()
end
end
Roact.mount(Roact.createElement(HealthBar), PlayerGui, 'HealthBar')
How would i go about lerping the bar at low health it sizes down and becomes red. Yellow for medium and green for full.