Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is this type of script acceptable?

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)

5 comments

0

if I would create a run script, I would do exactaly that

0

This is scripting helpers, not code review

0

its still helping scripts

0

code review is not the same as helping with an issue

0

theres a section in discord for code review

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.