local player = game.Players.LocalPlayer
local fuelBar = player.PlayerGui:WaitForChild("FuelBar")
local fullBar = fuelBar:WaitForChild("ImageFrame"):WaitForChild("Empty"):WaitForChild("Full")
local lantern = game.Workspace:WaitForChild(player.Name):WaitForChild("Lantern")
local fuel = lantern:WaitForChild("Fuel")
local function updateFuelBarUI()
local fuelRatio = fuel.Value / 75
fuelRatio = math.clamp(fuelRatio, 0, 1)
fullBar.AnchorPoint = Vector2.new(0.5, 0.5)
fullBar.Size = UDim2.new(fuelRatio * 0.972, 0, 0.75, 0)
fullBar.Position = UDim2.new(0.5, 0, 0.5, 0)
if fuel.Value == 0 then
fullBar.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
else
fullBar.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
end
end
local function toggleFuelBarVisibility(isLanternEquipped)
if isLanternEquipped then
fuelBar.Enabled = true
else
fuelBar.Enabled = false
end
end
spawn(function()
while true do
wait(0.1)
local isLanternEquipped = lantern.Parent == player.Character
toggleFuelBarVisibility(isLanternEquipped)
if isLanternEquipped then
updateFuelBarUI()
end
end
end)
game:GetService("ReplicatedStorage").UpdateFuel.OnClientEvent:Connect(function(newFuelValue)
fuel.Value = newFuelValue
updateFuelBarUI()
end)
This is my current code portraying within the video seen below. I just can’t seem to get the UI to reload upon respawn for when the lantern is equipped!
Any Support?