Hello! I’ve always struggled with UI’s and I need help trying to figure this one out. I don’t know what’s wrong with it, if you could help it would be great. Here’s my code.
local Player = game.Players.LocalPlayer
local UI = script.Parent.magic
local Character = Player.Character or Player.CharacterAdded:Wait()
local currentMagic = Character:WaitForChild("Humanoid"):WaitForChild("CharacterValues"):WaitForChild("Energy")
local function mapToRange(t, a, b, c, d)
return c + ((d-c)/(b-a)) * (t-a)
end
local TW = game:GetService("TweenService")--Get Tween Service
local Player = game:GetService("Players").LocalPlayer --Get The Player
local Humanoid = Character:WaitForChild("Humanoid") --Get The Player Humanoid
local healthbar = script.Parent.health -- Get The Health Bar
local function tween(Obj, Property)
game:GetService("TweenService"):Create(Obj, TweenInfo.new(.2), Property):Play()
end
task.spawn(function()
while true do
wait()
pcall(function()
--HealthText.Text = Character.Humanoid.Health
tween(healthbar,{Size = UDim2.new(Character.Humanoid.Health/Character.Humanoid.MaxHealth, 0, 0.516, 0)})
if Humanoid.Health == Humanoid.MaxHealth then
tween(healthbar,{Size = UDim2.new(0.436, 0, 0.516, 0)})
end
end)
pcall(function()
-- EnergyText.Text = Character.Humanoid.CharacterValues.Energy.Value
game:GetService("TweenService"):Create(UI,TweenInfo.new(.2),{Size = UDim2.new(currentMagic.Value/currentMagic.Parent:FindFirstChild("MaxEnergy").Value,0,0.482,0)}):Play()
if currentMagic.Value == currentMagic.Parent:FindFirstChild("MaxEnergy").Value then
game:GetService("TweenService"):Create(UI,TweenInfo.new(.2),{Size = UDim2.new(0.436,0,0.482,0)}):Play()
end
end)
end
end)