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

[SOVLED] | Keyboard Input help?

I've been trying to activate a remote function on a key press and it worked in studio, but when I joined the game, it didn't work.

So I tried to narrow down the possibilities of what it could be: I started off by Re-Writing the code (this time using ContextActionService instead of UserInputService), and it still didn't work, so I tried changing the players walk speed (instead of firing a remote function) and again, it worked in studio, but not in the player.

I'm not very adept at scripting (I'm just starting out ;P) so I don't know what the problem with it is. Here is my code:

local showDialog = game.ReplicatedStorage.ShowDialog

-- Will be used for the remote function later

isInRange = true


function sendSignInfo(actionName, userInputState, inputObject)
	if isInRange == true and userInputState == Enum.UserInputState.Begin then
		print("test")
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 100
	end
end


game.ContextActionService:BindAction("keyPress", sendSignInfo, false, Enum.KeyCode.E)

Send help if you know what the problem is!

Thanks, Kyleo.

4 comments

0

Some of the spacing is messed up from the post, I do (think) I have it formatted correctly. Also there are no errors in the output. ;P

0

Is this in a LocalScript?

0

No, regular script in an object, should it be in StarterPlayerScripts?

0

PlayerGui or Backpack would do fine

1 answer

✓ Accepted answer

Any scripts that deal with anything client side, like userImputService, must be in a LocalScript. Also from now on please use the a code block for your code (The little blue circle with "Lua" on it)

1 comment

0

Thanks! I should have guessed that it needed to be in a local script! ;P

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