Disclaimer - Been a long time since I did any RB coding!
I’m starting simple with a Sprint & Stamina bar feature for my character but am struggling with why my sprint function works only partially to set the walkSpeed.
local function sprint(shouldSprint)
print("Sprint pressed", shouldSprint)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 100
if shouldSprint then
print("Sprint!")
--humanoid.walkSpeed = 300
isSprinting = true
else
print("no sprint")
--humanoid.walkSpeed = 16
isSprinting = false
end
end
The function above is called by the user Pressing keyboard key (for now). And fires as I expect. Using the code above sets the Players WalkSpeed. However, if I try and use the commented part in the logic, to toggle between setting the two values, I get an error:
walkSpeed is not a valid member of Humanoid "Workspace.JayRey78.Humanoid"
What is happening here? Is there something I don’t understand about the “scope” of the variables inside the if?