I have been trying to make a run script for scripting practices and so far I have created a working run script. However, I want to know if this code is an acceptable format or does it need some improvement. Can someone please check through my code and tell me what I need to improve on and change?
local UserInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Running = 50 local Walking = 16 UserInputService.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then local Character = Player.Character local Humanoid = Character:FindFirstChild("Humanoid") --WaitForChild("Humanoid") works too. if Humanoid then Humanoid.WalkSpeed = Running end end end) UserInputService.InputEnded:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then local Character = Player.Character local Humanoid = Character:FindFirstChild("Humanoid") --WaitForChild("Humanoid") works too. if Humanoid then Humanoid.WalkSpeed = Walking end end end)
ur script pretty good but there's a second parameter in inputbegan which is a bool that returns true if ur typing in chat or a textbox.
local UserInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Running = 50 local Walking = 16 UserInputService.InputBegan:Connect(function(Input, Process) if Process then return end if Input.KeyCode == Enum.KeyCode.LeftShift then local Character = Player.Character local Humanoid = Character:FindFirstChild("Humanoid") --WaitForChild("Humanoid") works too. if Humanoid then Humanoid.WalkSpeed = Running end end end) UserInputService.InputEnded:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then local Character = Player.Character local Humanoid = Character:FindFirstChild("Humanoid") --WaitForChild("Humanoid") works too. if Humanoid then Humanoid.WalkSpeed = Walking end end end)
I usually don't put that in input ended because then can hold down shift then starting typing and release which will trick the script into thinking he was holding it the whole time.