I want my player to be able to run even after he dies.
After you die, the script doesn’t work anymore. There is no error in the output and I can’t really explain why it doesn’t work. I checked which if statement stops the script and found that Humanoid.MoveDirection.Magnitude is always 0 after I die.
I’ve searched for solutions but haven’t found anything that would help. I also added a function that redefines Humanoid after I die, thinking it might fix the problem. But it didn’t.
--
local NormalWalkSpeed = 15
local SprintSpeed = 40
local CameraEffect = true
local stamina = 200
local isRunning = false
local StaminaFrame = script.Parent
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local Camera = game.Workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key, gameProcessedEvent)
if key.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
end
end)
UIS.InputEnded:Connect(function(key, gameProcessedEvent)
if key.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if stamina > 0 then
if isRunning then
if Humanoid.MoveDirection.Magnitude > 0 then
--print("Magnutide")
Humanoid.WalkSpeed = SprintSpeed
stamina -= 0.5
StaminaFrame.Size = StaminaFrame.Size - UDim2.new(0.0006875,0,0,0)
end
else
Humanoid.WalkSpeed = NormalWalkSpeed
wait(2)
end
else
Humanoid.WalkSpeed = NormalWalkSpeed
wait(2)
end
if stamina < 200 then
if not isRunning then
stamina += 0.5
StaminaFrame.Size = StaminaFrame.Size + UDim2.new(0.0006875,0,0,0)
end
end
end)
Credit for the script: How to make a Sprint and Stamina System - Roblox Scripting Tutorial - YouTube
Most of this script is copy pasted from the script in this tutorial!