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

i wanna make it so when i'm not holding it stops but it still running fast - ?

local UserInpServ = game:GetService('UserInputService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
UserInpServ.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E then	
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 72
	else
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
	end
end)
-- help

2 comments

0

Please format with a code block.

0

done i need to go right now sorry, byee

1 answer

Formatting your code

Firstly, I formatted your code in a code block for you.

local UserInpServ = game:GetService('UserInputService') 
local ReplicatedStorage = game:GetService('ReplicatedStorage') 

UserInpServ.InputBegan:Connect(function(Input) 
	if Input.KeyCode == Enum.KeyCode.E then 
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 72 
	else 
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25 
	end 
end)

The issue

Basically, you need to check if the keycode was E when the input ends, which will detect that it was held and you can set the walkspeed back.

Here is a fixed script

local UserInpServ = game:GetService('UserInputService') 
local ReplicatedStorage = game:GetService('ReplicatedStorage') 

UserInpServ.InputBegan:Connect(function(Input) 
	if Input.KeyCode == Enum.KeyCode.E then 
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 72 
	end
end)

UserInpServ.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
	end
end)

Thanks

Thanks for reading, hope I helped.

:-)

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