DirectoryKeys["LeftShift"] = function()
local Dude = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
if Sprinting == false then
local PriorWalkSpeed = Dude.WalkSpeed
local PriorWR = WR.Value
local PriorStance = Stance.Value
Sprinting = true
Dude.WalkSpeed = 22
Stance.Value = 3
if PrimAnim == true then
WR.Value = 2
else
WR.Value = 1
end
WeaponReadiness()
StancePosition()
script.Parent.Parent.PlayerGui.WeaponUI.Frame.SPSDisplay.Text = "WalkSpeed: "..Dude.WalkSpeed
else
Sprinting = false
WR.Value = 3
Stance.Value = 3 -- These three numbers here are where the "memorized stances" go.
Dude.WalkSpeed = 13.5
WeaponReadiness()
StancePosition()
script.Parent.Parent.PlayerGui.WeaponUI.Frame.SPSDisplay.Text = "WalkSpeed: "..Dude.WalkSpeed
end
end
If I wanted to sprint only when holding the Left Shift button down, saving the WalkSpeed, WeaponReadiness level, and Stance level in between calling the function and beginning the sprinting, and then stop sprinting when I release the Left Shift button and then revert to the previous stats using the saved variables, how would I go about this?
Any attempts I've made either result in the stats not saving properly and any buttons that aren't shift (while left shift is held down) firing the function and breaking the sprint or re-activating it, or for some reason not being able to pull out my primary or secondary weapons and even bugging when trying to pull the second weapon out pressing "2", going as far as to continuously run in a single direction until right clicking...?
Any help would be greatly appreciated.
[Note: This code is what I began with up here. The code below is what I have currently.]
Mouse.KeyDown:connect(function(Key) -- Works; but the local Priors need to be redefined to whatever the stats are between the time the Left Shift
local Dude = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") -- is pressed and the time that the sprinting actually begins.
local PriorWalkSpeed = Dude.WalkSpeed -- code works otherwise.
local PriorWR = WR.Value
local PriorStance = Stance.Value -- For some reason the ability to draw primary and secondary have broken while sprinting.
-- Yay, more problems to fix! ... Just what I wanted... - _ -
if Key:byte() == 48 then
if Sprinting == false then
Sprinting = true
Dude.WalkSpeed = 22
Stance.Value = 3
if PrimAnim == true then
WR.Value = 2
else
WR.Value = 1
end
WeaponReadiness()
StancePosition()
script.Parent.Parent.PlayerGui.WeaponUI.Frame.SPSDisplay.Text = "WalkSpeed: "..Dude.WalkSpeed
Mouse.KeyUp:connect(function(Key)
if Key:byte() == 48 then
Sprinting = false
WR.Value = PriorWR
Stance.Value = PriorStance
Dude.WalkSpeed = PriorWalkSpeed
WeaponReadiness()
StancePosition()
script.Parent.Parent.PlayerGui.WeaponUI.Frame.SPSDisplay.Text = "WalkSpeed: "..Dude.WalkSpeed
else
end
end)
end
end
end)
Again, any assistance would be great.
To summarize: Holding Left Shift should swiftly save or overwrite the save of your current WalkSpeed, Stance and WR levels before going into the actual sprinting function. ONLY Left Shift should be handling Sprinting independently of everything else.
When Left Shift is released, it should end the Sprinting function by reverting to the previously saved or overwritten WalkSpeed, Stance and WR level to create a seamless sprinting system.

1 comment
Try defining at the start of the script a variable called oldspeed, and when you press a key, even before it sets the speed, it sets the oldspeed variable to the user's speed. Then, set the user's speed to the oldspeed variable.