I have these bars that scale along with the player’s stamina and health, and of course, they should only get bigger and smaller on the x-axis.
script.Parent.Health.Progress.Size = UDim2.new(math.floor(Character.Humanoid.Health)/100, 0, 1, 0)
Why is this line of code not working?
Full script or any error please? It might not be that code, but whatever function/loop is related to it isn’t running it.
PS, UDim2.fromScale() is a thing.
-- VARIABLES
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local UserInputService = game:GetService("UserInputService")
local rs = game.ReplicatedStorage
local Network = rs.Network
local RefreshEvent = Network.Remotes.Events.Refresh
local Stamina = 100
local Running = false
local WalkSpeed = 16
local LevelFrame = script.Parent.Level
local LevelText = LevelFrame.Text
local Running = false
-- FUNCTIONS
Character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
script.Parent.Health.Progress.Size = UDim2.new(math.floor(Character.Humanoid.Health)/100, 0, 1, 0)
end)
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
Running = true
Character.Humanoid.WalkSpeed *= 2
while Stamina > 0 and Running do
Stamina -= 1
--print(Stamina)
if Stamina == 0 then
script.Parent.Stamina.Progress.Visible = false
else
print("tweening")
script.Parent.Stamina.Progress:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
end
wait()
if Stamina == 0 then
Character.Humanoid.WalkSpeed = WalkSpeed
end
end
end
end)
UserInputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
Running = false
Character.Humanoid.WalkSpeed = WalkSpeed
while Stamina < 100 and not Running do
script.Parent.Stamina.Progress.Visible = true
Stamina += 1
--print(Stamina)
script.Parent.Stamina.Progress:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
wait()
if Stamina == 0 then
Character.Humanoid.WalkSpeed = WalkSpeed
end
end
end
end)
local Remainder = 10
local function Calculate(XP)
local Count = 0
local Exp = XP
Level = 0
local TotalUsed = 0
-- MAIN LOOP
repeat
Count += 1
Exp -= Count*10
Level += 1
task.wait()
until Exp < 0
--------
Level -= 1
print("Level: "..Level)
local Counter = 0
Exp = XP
Remainder = Exp
repeat
Counter += 1
Remainder -= Counter*10
task.wait()
until Counter == Level
print("Remainder: "..Remainder)
end
RefreshEvent.OnClientEvent:Connect(function()
local PlayerData = rs.Players:WaitForChild(Player.Name)
local LevelString = PlayerData.Level.Value
Calculate(PlayerData.Experience.Value)
local Needed = (Level + 1)*10
LevelText.Text = "Lvl "..tostring(LevelString).." XP "..tostring(Remainder).."/"..Needed
script.Parent.Level.Progress:TweenSize(UDim2.new(Remainder/Needed*.961, 0, .625, 0), "Out", "Linear", 0)
end)
There are no errors, I’ll try using udim2.fromscale now
To me, it seems fine. Try putting a print() to see if the function itself is even being run. Might be wiser to use Humanoid.HealthChanged?
UDim2.fromScale is not the solution by the way, it’s just a neater more compact touch that I recommend.
Did you test taking damage first?