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.
Ok so heres the code.When you press shift the walkspeed turns to 50 aka your running and when your not pressing shift your speed goes to 20 aka walking.Im a new scripter so it might not work.But this is the script.
local zeb=game:GetService("UserInputService") zeb.InputBegan:connect(function(key,processed) if no proc and Input.Keycode=enum.Keycode.Shift then game.Players.LocalPlayer.Humanoid.WalkSpeed=50--change if you want end zeb.InputEnded:connect(function() game.Players.LocalPlayer.Humanoid.Walkspeed=25--the devault walkspeed end) end)
Also tell me if this works and tell me how good of a scripter i am :D.If it dont work tell me what i need to fix