So this script sometimes works, sometimes doesn’t, it’s all random right now.
No errors on output.
Script:
local t
local b = Instance.new("BindableEvent")
-- Services
local uis = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
-- Variables
local cam = game.Workspace.CurrentCamera
local stamina = game.Players.LocalPlayer:WaitForChild("StatsFolder"):WaitForChild("Stamina")
local char = game.Players.LocalPlayer.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local regen = game:GetService("ReplicatedStorage").RemoteEvents.Regen
local stopRunningEvent = game:GetService("ReplicatedStorage").RemoteEvents.StopRunning
-- Events
local staminaRemote = game:GetService("ReplicatedStorage").RemoteFunctions.StaminaEvent
local runStop = game:GetService("ReplicatedStorage").RemoteEvents.StopRunning
-- Functions
local function createtween(obj, newVal)
local tweenInfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
local tween = tweenService:Create(obj, tweenInfo, {FieldOfView = newVal})
tween:Play()
end
local function onRequestReceived()
b:Fire("received")
end
local function checkRegen()
while wait(0.35) do
if stamina.Value ~= 100 then
if tick() - t >= 3 then
regen:FireServer()
end
end
end
end
-- Event
uis.InputBegan:Connect(function(input, gpe)
if gpe == false then
if uis.KeyboardEnabled == true then
if input.KeyCode == Enum.KeyCode.LeftShift then
local canRun = staminaRemote:InvokeServer("run", true)
if canRun then
onRequestReceived()
hum.WalkSpeed = 25
createtween(cam, 85)
end
elseif input.KeyCode == Enum.KeyCode.Space then
onRequestReceived()
staminaRemote:InvokeServer("jump", false)
end
end
end
end)
uis.InputEnded:Connect(function(input, gpe)
if gpe == false then
if uis.KeyboardEnabled == true then
if input.KeyCode == Enum.KeyCode.LeftShift then
staminaRemote:InvokeServer("run", false)
onRequestReceived()
hum.WalkSpeed = 16
createtween(cam, 70)
end
end
end
end)
runStop.OnClientEvent:Connect(function()
game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 16
createtween(cam, 70)
end)
stamina.Changed:Connect(function(prop)
if prop == stamina.Value then
if stamina.Value < 10 then
hum.JumpPower = 0
elseif stamina.Value >= 10 then
hum.JumpPower = 50
end
end
end)
b.Event:Connect(function(event)
if event then
if event == "received" then
t = tick()
end
else
error("No event specified.")
end
end)
stopRunningEvent.OnClientEvent:Connect(function(trig)
if trig then
b:Fire()
else
staminaRemote:InvokeServer("run", false)
onRequestReceived()
hum.WalkSpeed = 16
createtween(cam, 70)
end
end)
local f = coroutine.wrap(checkRegen)
f()