Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is this type of script acceptable?

Asked by
QWJKZXF 88
3 years ago

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)

0
if I would create a run script, I would do exactaly that Leamir 3138 — 3y
0
This is scripting helpers, not code review incapaz 195 — 3y
0
its still helping scripts HappyTimIsHim 652 — 3y
0
code review is not the same as helping with an issue incapaz 195 — 3y
0
theres a section in discord for code review greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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.

Ad

Answer this question