I'm in the process of making a sprint script for my Roblox game with a stamina function and everything, but I ran into an error halfway through development of the script. First of all, here's the script I'm using:
if script.Parent.ClassName == ("Model") then
script.Parent.Humanoid.WalkSpeed = (15)
end
local se = game:GetService("UserInputService")
local hu = script.Parent.Humanoid
local sa = script.Stamina
local st = script.Toggle
function DegenerateStamina()
st.Value = true
end
function RegenerateStamina()
st.Value = false
end
se.InputBegan:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
hu.WalkSpeed = (25)
DegenerateStamina()
repeat wait() until
se.InputEnded:connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
hu.WalkSpeed = (15)
RegenerateStamina()
end
end)
end
end)
The Stamina function isn't finished yet, I just have it set to toggle a value when the character is/isn't sprinting. I have the code in a local script, with two values inside the script: One to keep track of how much stamina the player has (An integer value), and another to detect if the player is sprinting or not so it can decide whether or not to deduct stamina (A bool value). These should all be defined within the script.
Anyways, whenever I try to run the script, I get this error:
15:58:53.836 - Stamina is not a valid member of LocalScript 15:58:53.837 - Stack Begin 15:58:53.837 - Script 'Workspace.EnderGamer358.Sprint', Line 7 15:58:53.838 - Stack End
It's saying that the Stamina value, the one that keeps track of how much stamina my player has, either isn't defined correctly or doesn't exist, even though I checked several times through and thought I got everything perfect. Any errors in my script that I'm just missing?

1 comment
Ah, yes. Maybe my brain could have actually worked for once and said "Hey, maybe the reason it isn't accepting the values is because they haven't loaded in yet!" Anyways, thanks for your help!