Ok so I’m trying to make a stamina bar script for my game and I found a script that works good. I’ve edited it to my liking, but the stamina bar script only stuck to the specific screen size it was on while I was editing it. I’m trying to fix it, but I’m not that good at scripting to understand it yet. I’ve tried to ask for help from people but no luck yet and I’ve also tried to learn about the funtions but I still don’t really understand it.
The error says “Players.bringtixbackalready.PlayerGui.Stamina.Bar.StaminaClient:50: attempt to perform arithmetic (mul) on number and UDim2” and I know it means that i’m trying to do a math thing with a thing that doesn’t work with it, but I don’t know how to fix it. The people that at least guided me in the right direction said that I had to find the current value of the stamina bar for it to work. How can I do that?
Script:
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local UIS = game:GetService("UserInputService")
local Stamina = 20
local IsRunning = false
local staminaValue = Stamina
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
if Stamina >= 1 then
IsRunning = true
Character.Humanoid.WalkSpeed = 18
while IsRunning == true do
if Stamina <= 0 then
IsRunning = false
Character.Humanoid.WalkSpeed = 12
script.Parent:Destroy()
elseif Stamina >= 0 then
Stamina = Stamina - 0.25
end
wait(1)
end
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
if Stamina <= 0 then
IsRunning = false
Character.Humanoid.WalkSpeed = 12
script.Parent:Destroy()
end
IsRunning = false
Character.Humanoid.WalkSpeed = 12
end
end
end)
while true do --Part of script where the error is
wait(0.1)
staminaValue = Stamina
script.Parent:TweenSize((UDim2.new(0, staminaValue * script.Parent.Size)), Enum.EasingDirection.Out, Enum.EasingStyle.Back)
end
I’ve tried to read up on some of the things mentioned in the error, but I’m one of those people who learn better from hands-on stuff and demonstrations that are engaging ;-;
the size of “script.Parent” gives 2 values, the x and y value of the size, choose one to the script (I don’t know how works your script because I don’t have so much time, so try both to see what’s the correct)
Thanks for the help, first one wielded this error: “x is not a valid member of UDim2”
I’ll try the other one now
Edit: second one didn’t work aswell and said “y is not a valid member of UDim2”
Sorry, i’m not that good at tweens yet but this is the error it gave me: “Players.bringtixbackalready.PlayerGui.Stamina.Bar.StaminaClient:49: attempt to call missing method ‘create’ of table”
Here is what I put:
while true do
wait(0.1)
CurrentStamina -= 1
TweenInfo:create(script.Parent, Enum.EasingStyle.Back, {Size = UDim2.new(0, 0, CurrentStamina / Stamina, 0)}):Play()
end