I’m standing on a spot and holding shift and I start to lose stamina but I’m not supposed to lose stamina.
Stamina Script:
local player = game.Players.LocalPlayer
local char = player.Character
local UIS = game:GetService(“UserInputService”)
local stamina = 250
local isRunning = false
stamina = math.clamp(stamina, 0, 250)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
char.Humanoid.WalkSpeed = 20
while stamina > 0 and isRunning do
stamina = stamina -1
script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1, 0), "Out", "Linear",0)
wait()
if stamina <= 0 then
char.Humanoid.WalkSpeed = 8
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
char.Humanoid.WalkSpeed = 8
while stamina < 250 and not isRunning do
stamina = stamina +0.5
script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1, 0), "Out", "Linear",0)
wait()
if stamina <= 0 then
char.Humanoid.WalkSpeed = 8
end
end
end
So your issue is that standing still they still lose stamina?
Maybe you could check if they are moving or on every loop you run “is the players position in a different spot thats far enough to count as moving?”
Can you paste your entire script in a code block for me so I can edit it?
The post you made doesn’t have it all in a code block so it’s hard for me to work with
local player = game.Players.LocalPlayer
local char = player.Character
local UIS = game:GetService("UserInputService")
local stamina = 250
local isRunning = false
stamina = math.clamp(stamina, 0, 250)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
char.Humanoid.WalkSpeed = 20
while stamina > 0 and isRunning do
stamina = stamina -1
script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1, 0), "Out", "Linear",0)
wait()
if stamina <= 0 then
char.Humanoid.WalkSpeed = 8
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
char.Humanoid.WalkSpeed = 8
while stamina < 250 and not isRunning do
stamina = stamina +0.5
script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1, 0), "Out", "Linear",0)
wait()
if stamina <= 0 then
char.Humanoid.WalkSpeed = 8
end
end
end
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local userinputservice = game:GetService("UserInputService")
local stamina = 250
local isRunning = false
stamina = math.clamp(stamina, 0, 250)
userinputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid.MoveDirection.Magnitude > 0 then
isRunning = true
character.Humanoid.WalkSpeed = 20
while stamina > 0 and isRunning do
stamina = stamina - 1
script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1, 0), "Out", "Linear", 0)
wait()
if stamina <= 0 then
character.Humanoid.WalkSpeed = 8
end
end
end
end
end)
userinputservice.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
character.Humanoid.WalkSpeed = 8
while stamina < 250 and not isRunning do
stamina = stamina + 0.5
script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1, 0), "Out", "Linear", 0)
wait()
if stamina <= 0 then
character.Humanoid.WalkSpeed = 8
end
end
end
end)
Let me know if this works, dont replace your code entirely with this, make a new script and put this in it and check, since I don’t know exactly what you’re working with