while power > 0 and Character.Humanoid.MoveDirection.Magnitude > 0 do
power = power - .02
script.Parent.Parent.Parent.ScreenGui.stamina.gauge.Size = UDim2.new(power / 10, 0, 0.674, 0)
--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)
wait()
if power <= 0 then
Character.Humanoid.WalkSpeed = 16
running = false
PlayAnim:Stop()
end
end
My script is in startergui
i Creating a script that reduces the gauge when walking.
so this means that this script does not work.
But I can’t detect walking
How can I solve this problem?
If you need any information, I will provide you with more.
I think I know what’s happening here. You are using a while loop which check for the power. As soon as the power is less then 0 it stops, problem is that the if statement also checking for the power and responsible for changing the humanoids walkspeed, can’t run as the while loop stops before.
Does this work?
while wait() do
if Character.Humanoid.MoveDirection.Magnitude >= 0 then return end
power = power - .02
script.Parent.Parent.Parent.ScreenGui.stamina.gauge.Size = UDim2.new(power / 10, 0, 0.674, 0)
--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)
if power <= 0 then
Character.Humanoid.WalkSpeed = 16
running = false
PlayAnim:Stop()
return
end
end
I don’t know if this will help with your new problem but if your script is in starter gui, how are you able to do character.Humanoid? wouldn’t you have to do character:WaitForChild(“Humanoid”)?
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Anim = Instance.new('Animation', Character.Humanoid)
Anim.AnimationId = 'rbxassetid://15710495400'
local function sprint()
local p = Character.Humanoid:LoadAnimation(Character.Humanoid.Animation)
if sprinting then
p:Play()
sprinting = false
else
PlayAnim:Stop()
sprinting = true
end
end
button.MouseButton1Click:Connect(sprint)