- What do you want to achieve? Keep it simple and clear!
I want to insert multiple players names into a single dictionary where there values will be true or false.
Then i want to be able to change those individual values by the individual player pressing a button.
- What is the issue? Include screenshots / videos if possible!
When inserting the newPlayer.Name into a variable called name, the result in print is that the key in dictionary is actually only the word name. creating a wrong name for the key, also creating a individual key when i need a key per player.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I am following a tutorial from the book “The official Roblox guide, Coding with Roblox Lua” to do the insert to dictionary function but does not work.
Sample Code (not sure how to put in code format to read or is automatic) -
– code has been altered so names of variables and dictionaries are not exact.
– first part of question. how to add in dictionary the player name properly
dictionaryName = {
}
function establishPlayer(newPlayer)
local name = newPlayer.Name
dictionaryName.name = false
for i, v in pairs(dictionaryName) do – reads the players names every time added player joins. but the result is only printing the word “name” because of code dictionaryName.name does not use the variable name, is using the literal word name to insert the word “name” as a dictionary variable
print(i) – results in out put statement (13:55:34.626 name - Server)
end
end
Players.PlayerAdded:Connect(dictionaryName)
– end first part
– second part
– second part takes the errored dictionary value the word “name” is used instead of player’s name, but the code does change the value of the key from the dictionary. I will need to know how to use variable to look up dictionary variable (player name) to change there individual value.
game.ReplicatedStorage.HideTest1.OnServerEvent:Connect(function(player)
local name = player.Name – does this work?
if dictionaryName.name == false then
dictionaryName.name = true
else
dictionaryName.name = false
end
end)
– end second part
Would appreciate if in your responses used code as examples so i have exact answers. Thank you for your help. If you have questions i will answer. If this is fixed with your help i will post a response question with the uses of this dictionary key with value in its actual use in the script. Thanks again!