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

How To Detect If First/Second Player of the Table Pressed the Key?

Asked by
Borrahh 265 Moderation Voter
4 years ago
Edited 4 years ago

Edit: I just want to know, how to check which player Pressed the key

So Basically, If First player on the table, Pressed the key, let's say a print happens. How can I Do That?

I tried = if i[1].key.KeyCode == Enum.KeyCode[playersInRoomOne] then but it's not working, I don't get any errors

Local Script

local remote = game.ReplicatedStorage.RoomsStringValues.RoomOne.RoomOneEvent
local UIS = game:GetService("UserInputService")
local playerOneString = game.ReplicatedStorage.RoomsStringValues.RoomOne.PlayerOne
local playerTwoString = game.ReplicatedStorage.RoomsStringValues.RoomOne.PlayerTwo
local playersInRoomOne = {playerOneString, playerTwoString}


local allTheKeyWords = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X","Y","Z"}
local randomKeyChooser = allTheKeyWords[math.random(1, #allTheKeyWords)]

local isThereAWinner = false


print("Players in game are: "..table.concat(playersInRoomOne, ", "))

UIS.InputBegan:Connect(function(key)
-- The Code should be here for player 1
    if key.KeyCode == Enum.KeyCode[randomKeyChooser] then
        print("Player 1 pressed it")
    else
        print("Player 2 pressed it")
    end

end)
0
LocalScript -> Remote Event/Remote Function -> Server Script. You can only detect input from a specific player using a LocalScript. If you want to send the input to the server, you will have to use a RemoteEvent to send the input, and a ServersScript to handle the repsonse. killerbrenden 1537 — 4y
0
I know that, this is a local script, now pls read my question, and if you know the answer, let me know Borrahh 265 — 4y
0
Please put more information so people know that this is a LocalScript as there is nothing that shows you are using a LocalScript. killerbrenden 1537 — 4y
0
Ok My Bad, can you help me :/ Borrahh 265 — 4y

2 answers

Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

killerbrenden is probably right. You'd probably want a remote that sets a variable to true, that variable meaning that the player pushed the button. However, if this is the right answer, you might wanna get killerbrenden to put an answer in, cause it's what he suggested

0
I get that as I said on the comments, My Question is, How can I check if first player pressed the Key? Forget About Remotes and other stuff Borrahh 265 — 4y
0
exactly like i said, use a variable, use UserInputService to detect if the player pressed the key, and when the key's pressed, set the variable to true, repeat for the other player zadobyte 692 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I'll take a guess. A pretty good way is creating a blank table:

local blank = {}

I used a click detector in place, but it should work the same.

Get when the player pressed the key (or in my case clicked the part) and create a function:

script.Parent.ClickDetector.MouseClick:Connect(function(player)

end)

Put in the function something like this:

table.insert(blank,player.Name)

for i, v in pairs(blank) do

    print(i,v)

end

The total script:

local blank = {}

script.Parent.ClickDetector.MouseClick:Connect(function(player)

table.insert(blank,player.Name)

for i, v in pairs(blank) do

    print(i,v)

end

end)
0
Uh not really, I don't know if I'm not clear enough of what I'm asking, I want to check who Clicked the Key, The Player's Name... Borrahh 265 — 4y

Answer this question