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

This script that's supposed to make the humanoid go faster when shift is held does not do anything?

What I am making, is that you can hold down shift, or X on an Xbox 360 controller, to go twice the normal humanoid walkspeed. The issue i'm having is that when I go to test this, it does not do what it's supposed to do, and no errors and reported in the output! Here's the code below:

--Shift to run!
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local userInputService = game:GetService("UserInputService")

local function Run()
	humanoid.WalkSpeed = 32
end

if userInputService:IsKeyDown(16) or userInputService:IsGamepadButtonDown(2) then
	Run()
end

1 answer

Hi Atomic,

You forgot to connect the InputBegan event to the function to make it run. Here's how you would do that:

--Shift to run!
local player = game.Players.LocalPlayer
-- Removed Humanoid because it's better to define inside of the function since it gets updated and it just looks neater.
local userInputService = game:GetService("UserInputService")

function Run(obj, gp)

	local char = player.Character or player.CharacterAdded:Wait();
	local hum = char:WaitForChild("Humanoid");

	-- Shift For Computer Users --
	if obj.KeyCode == Enum.KeyCode.LeftShift and not gp then
		hum.WalkSpeed = 32;
	end
	-- Shift For Computer Users --


   -- Shift For Xbox Users (Not entirely sure, just followed Wiki since I've never done it before) --	
	if obj.UserInputType == Enum.UserInputType.Gamepad1 then
		if obj.KeyCode == Enum.KeyCode.ButtonX then
			hum.WalkSpeed = 32;
		end
	end
   -- Shift For Xbox Users (Not entirely sure, just followed Wiki since I've never done it before) --	

end

userInputService.InputBegan:Connect(Run);

##Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

1 comment

0

Sorry for such a ridiculously late response but it does not work. However, I'm still learning and failure is always a part of learning something new!

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