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

Speed Script not working, I want the ability to press e and have my player speed up to 200. Help?

I'm trying to create a script whereby when the key "e" is pressed the player's speed is adjusted to 200 and when the key "e" is released the speed is adjusted back to normal.

Player = game.Players.LocalPlayer
if Mouse.KeyDown:connect(function(key)
    if key == "e" then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 200
    end
end)

3 comments

2

Clearly you do not understand Lua syntax, you should take a look at the wiki or the PiL as a reference

0

Clearly you don't understand this is a place for people to learn. If someone's asking a question here, it's probably because the forums and wiki crap made no sense to them, and they would like some personal help from people with experience.

0

Yes, however how they made it this far and want to do something a bit more complex like make a player do something when "E" is pressed is insane. All of this is covered in the wiki's tutorial which tells you how to manipulate a brick.

1 answer

Do not use if ..:Connect only use ...:Connect, :connect and Mouse.KeyDown/Up is deprecated. use :Connect and UserInputService.InputBegan/InputEnded.

Example:


 --< LocalScript

local uis = game:GetService("UserInputService") -- service to detect key's
local plr = game.Players.LocalPlayer -- get local player
local char = plr.Character or plr.CharacterAdded:Wait() -- wait for character added / get char

uis.InputBegan:Connect(function(input,proc)
	if not proc and input.KeyCode == Enum.KeyCode.E then -- On press E
		char:WaitForChild("Humanoid").WalkSpeed = 200 -- Wait for humanoid and set speed
	end
end)

-- You want to reset speed on stop walking? use uis.InputEnded
 --< You can remove this
uis.InputEnded:Connect(function(input,proc)
	if not proc and input.KeyCode == Enum.KeyCode.E then -- Detect if key Up
		char:WaitForChild("Humanoid").WalkSpeed = 16
	end
end)

What is UserInputService?

  • The UserInputService is a service used to detect and capture the different types of input available on a user’s device.

What is UserInputService.InputBegan?

  • The InputBegan event fires when a user begins interacting via a Human-Computer Interface device (mouse button down, touch begin, keyboard button down, etc.).

What is UserInputService.InputEnded?

  • The InputEnded event fires when a user stops interacting via a Human-Computer Interface device (Mouse button down, touch begin, keyboard button down, etc). This is useful when tracking when a user releases a keyboard key, mouse button, touchscreen input, etc. This event can be used along with UserInputService.InputBegan and UserInputService.InputChanged to track when user input begins, changes, and ends.

What is proc?

  • gameProcessedEvent / Indicates whether the game engine internally observed this input and acted on it. Generally this refers to UI processing, so if a button was touched or clicked from this input, gameProcessedEvent would be true. This is also true for input events connected via ContextActionService

This is in wiki.

Hope it helped :)

Wiki pages:

- UserInputService

- WaitForChild


Solved your problems? put [SOLVED] in title or accept a answer.

5 comments

0

Actually you won't need to call :WaitForChild() when they press :p

0

And the first bit of your answer is just telling OP to do x and not y because you say so. Maybe a syntax explanation would be nice

0

There is also the UserInputService.InputEnded event where in this case you would set the WalkSpeed back to normal (default: 16)

0

Other than those statements, good answer!

0

This is a good answer though.

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