How to detect the player from an object value?

hello devs. i am making a multiplayer game. and im making a system that detects who is player 1 and who is player 2. but i cant figure out how to get the player from an object value.



i tried using other forums but i didint figure out how to do it. please help.

2 Likes

If the objectvalue.Value is a player then why don’t you just use that. I don’t understand the question.

2 Likes

If the player1 value is set to the player then try this:

local player = workspace.Players.Player1.Value

its not set the player. its set to the character actually.

my mistake i forgot to say that the object value is a character not a player

Then try this:

local player = game.Players:GetPlayerFromCharacter(workspace.Players.Player1.Value)

Then set it to the player or just do Players:GetPlayerFromCharacter(character)

it works but theres one problem. it doesnt detect the player 2. since the argument is nil. is there a way i can make it always detect? until the object value is not equal to nil?

Did you set the player2 value to the second player character?

if so try this (Make sure that there is a value named “Player2” just like “Player1”)

local player = game.Players:GetPlayerFromCharacter(workspace.Players.Player2.Value)
1 Like
repeat
task.wait()
until objectValue.Value ~= nil
--Run code
2 Likes

how do i do that into a variable?

oh wait nvm i think i got it. ------------------------

it works. thanks. -------------------------

What do you mean by that comment?

oh wait never mind. it just gave me an error when i tried it in 2 player testing.

What error did you get would you mind adding?

i maybe i typed it wrong? but i dont know.
image

Show us the code where you’re running :WaitForChild() that doesn’t have anything to do with my previous code.

also this is what i typed. maybe i did it wrong?

Try changing the player variable to this

local player = game.Players:GetPlayerFromCharacter(workspace.Players.Player2.Value)