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

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

Asked by 5 years ago

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)
2
Clearly you do not understand Lua syntax, you should take a look at the wiki or the PiL as a reference User#24403 69 — 5y
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. Knineteen19 307 — 5y
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. Conmmander 479 — 5y

1 answer

Log in to vote
2
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

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.
0
Actually you won't need to call :WaitForChild() when they press :p User#24403 69 — 5y
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 User#24403 69 — 5y
0
There is also the UserInputService.InputEnded event where in this case you would set the WalkSpeed back to normal (default: 16) GoldAngelInDisguise 297 — 5y
0
Other than those statements, good answer! Knineteen19 307 — 5y
0
This is a good answer though. Conmmander 479 — 5y
Ad

Answer this question