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

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

I mean.

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

Would this work?

2 answers

✓ Accepted answer

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.

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

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