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

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

Asked by
BlagEz 26
5 years ago

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--
0
what do you mean by "only go to a certain player"? like only one player can have the option to press R? chomboghai 2044 — 5y
0
make a variable, if it is true then it goes only to that player. greatneil80 2647 — 5y
0
easy fix ^^ greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

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)
0
Thanks alot this helped me understand what was going on. BlagEz 26 — 5y
Ad

Answer this question