Greetings,
I’m trying to make a sprint script with a skill system to which you add points to increase the stamina and speed. But when the value is changed, it doesn’t do anything. It stays the same. How can I fix this?
local maximumstamina = script.Stamina.Value --stamina
local speed = script.Speed.Value --running speed
local normalspeed = 11 --normal speed
local staminadrain = 1 --stamina drain per second
local staminaregen = script.StaminaRegen.Value --stamina regeneration per second
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
local stamina = MAX_STAMINA
local isRunning = false
local function updateStamina(deltaTime)
if isRunning then
stamina = math.max(stamina - staminadrain * deltaTime, 0)
else
stamina = math.min(stamina + staminaregen * deltaTime, maximumstamina)
end
end
local function updateSpeed()
if isRunning and stamina > 0 then
humanoid.WalkSpeed = speed
else
humanoid.WalkSpeed = normalspeed
end
end
userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = true
end
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
end
end)
while true do
local deltaTime = wait(1/60)
updateStamina(deltaTime)
updateSpeed()
end