Hello! I am VERY new to LUA scripting and Roblox so please forgive my ignorance on this matter!
What I would like to accomplish is to have a StringValue added to each player as they join the game. This value will be accessed throughout the game to perform some conditional checks. I have coded the following which does add the StringValue under my player:
while true do
game.Players.PlayerAdded:Connect(function(playerName)
local stringVal = Instance.new('StringValue', playerName)
stringVal.Name = "playerUnitType"
stringVal.Value = "Civ"
end)
wait(1)
end
When I Play a test game it does indeed add a StringValue with the correct name and value as above. However, my question is how do I then access that StringValue from this script or other scripts? I tried some things such as making stringVal global instead of local but I still was not able to successfully do basic things such as print the Value or Name of the StringVal from outside of the function or the while loop.

1 comment
This makes perfect sense. Thank you! I think what was confusing me was the PlayerAdded event. I didn't understand that event will fire automatically every time somebody joins. My logic was that we need a while loop to constantly check if somebody had joined, but now that I understand that the event fires automatically every time a player joins it makes much more sense.