My Left Shift running works, but it makes the player keep running instead of stopping when they let the LShift button go. Can someone tell me what is wrong?
The localscript for the stamina and the stam bar:
local CAS = game:GetService("ContextActionService")
local RE = game:GetService("ReplicatedStorage"):WaitForChild("RE")
local fill = script.Parent:WaitForChild("top"):WaitForChild("fill")
local stam = 50
local speed = 16
local sprinting = false
local function sprint (str,state,object)
if stam <1 then return end
speed = state == Enum.UserInputState.Begin and 24 or 16
sprinting = state == Enum.UserInputState.Begin
while sprinting and stam > 0 and wait(.1) do
stam = stam - 1
fill:TweenSize(UDim2.new(stam/50, 0, 1, 0),"Out","Quint", .1, true)
RE:FireServer('sprint', (speed))
end
sprinting = false
speed = 16
RE:FireServer('sprint', (speed))
wait(1)
while not sprinting and stam < 50 and wait (.5) do
stam = stam+0.5
fill:TweenSize(UDim2.new(stam/50, 0, 1, 0), "Out", "Quint", .1, true)
end
end
CAS:BindAction("sprint", sprint, true, Enum.KeyCode.LeftShift)
script inside of serverscriptservice:
local RE = game:GetService("ReplicatedStorage"):WaitForChild("RE")
local stam = game.StarterGui.ScreenGui.stam
RE.OnServerEvent:connect(function(player, request, data)
if request == 'sprint' then
player.Character.Humanoid.WalkSpeed = data[1]
end
end)
PS: I have a RemoteEvent inside the ReplicatedStorage.

2 comments
Well I haven't use ContextActionService but all I know is UserInputService.
you might need while true do or some sort of debounce