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

Choosing a player in Game:GetService("Players") with a variable?

Asked by 5 years ago

I mean.

local players = game:GetService("Players")
local nameplayer = players:GetPlayerFromCharacter(character)
local player = game:GetService("Players").nameplayer

Would this work?

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Here's your answer

local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(character)

But I should say, third line of yours is so wrong. You can't use content of variable like .nameplayer, that would check for a player named "nameplayer". You should use :FindFirstChild(nameplayer) or [nameplayer]. Also, nameplayer in your second line is player, not name of player. For name of player you would need players:GetPlayerFromCharacter(character).Name Often, character has same name with player but still, GetPlayerFromCharacter is a good practice.

Ad
Log in to vote
0
Answered by 5 years ago

Yes it would but you would not need the third variable. The second variable would suffice for the player.

Answer this question