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

How can i make a KeyDown/KeyCode script only go to a certain player in game?

I was told that if u wanted a KeyDown/KeyCode script to be in your game you would have to direct it to everyone in that game. But i've seen a bunch of other games where this isn't true. Here is a script for an Ex.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
	if Key == "r" then
		print("you have pressed r")
	end
end)


--note that everyone can press r for "you have pressed r"  to appear in the output--
--I know KeyDown is deprecated, so if you have a KeyCode you can do that instead--

3 comments

0

what do you mean by "only go to a certain player"? like only one player can have the option to press R?

0

make a variable, if it is true then it goes only to that player.

0

easy fix ^^

1 answer

✓ Accepted answer

Just check if the LocalPlayer's name is the name of the certain player you want to give it to

local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input)
       if input.KeyCode == Enum.KeyCode.R and player.Name == 'chexyalani' then
              print('chexyalani has pressed R')
       end
end)

1 comment

0

Thanks alot this helped me understand what was going on.

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