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

How to I put a variables string value into game.Players.().TeamColor.Name?

https://gyazo.com/7a9a3a06738f9965af349ccfaa76023c

Not sure what to call it, but by "location part" I mean something around the lines of game.Workspace.etc I cannot figure out how to put the string value of "clicker" into game.Players.(clicker).TeamColor.Name

clicker = playerWhoClicked.Name
if game.Players.(clicker).TeamColor.Name == "Dark stone grey" then

1 comment

0

You rarely want the name of an object more than the object itself. It makes more sense to keep that object around than its name.

2 answers

✓ Accepted answer

If clicker is a string and you know it's a valid player on the server then use square brackets or :FindFirstChild your code should then be:

clicker = playerWhoClicked.Name
if game.Players[clicker].TeamColor.Name == "Dark stone grey" then
-- Code here
end

OR

clicker = playerWhoClicked.Name
if game.Players:FindFirstChild(clicker).TeamColor.Name == "Dark stone grey" then
-- Code here
end

Hope this helps, if it does please vote up and accept as answer, if it doesn't comment how and I'll fix it ASAP.

4 comments

0

The first one didn't work, but the second one did. Thanks for the help!

0

I just joined, so it will not let me up vote until I get some positive reputation. Sorry :/

0

Simlord, hit Accept answer if he adequately answered the question. It gives both of you some reputation

0

Yeah, I can't find that option.

Assuming playerWhoClicked is a Player object, you can access the properties of it directly:

if playerWhoClicked.TeamColor == BrickColor.new("Dark stone grey") then
	-- code here
end

Hit "Accept Answer" if this helped!

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