Hello, people.
I’m having quite an issue with dictionaries and the fact that trying to assign a value to only one variable in a dictionary (which itself is inside a dictionary) assigns it throughout multiple different dictionaries. For whatever reason, this issue isn’t present when modifying variables only a level deeper into the dictionary (which in my case would be “attributesCharacter”).
I would like for the event in the code below to only modify variables from the given character’s dictionary. Instead, it modifies every characters’ dictionary in the same manner.
I have ensured that the event is only being called once when needed and that there is no other script that could be messing with the result.
local players = game:GetService("Players")
local moduleFolder = game.ReplicatedStorage:WaitForChild("Modules")
local attributesModule = require(moduleFolder:WaitForChild("Attributes"))
local eventFolder = game.ReplicatedStorage:WaitForChild("Events")
local mouseButtonPressedEvent = eventFolder:WaitForChild("MouseButtonPressed")
-- "attributesModule" is equal to what's shown below.
attributesModule = {
character1 = {
Client = {...},
Server = {...},
},
character2 = {
Client = {...},
Server = {...},
},
...,
}
mouseButtonPressedEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local attributesCharacter = attributesModule[character]
-- Assigns to every characters' dictionary because "Server" already exists (not intended)
attributesCharacter["Server"]["NewVariable"] = "Value"
-- Assigns to given character's dictionary (works as intended)
attributesCharacter["Tester"] = {}
-- Assigns to given character's dictionary ONLY since (I'd assume) it fails for all other characters since "Tester" doesn't exist in those dictionaries
attributesCharacter["Tester"]["NewVariable"] = "Value"
--[[
-- I've noticed that reassigning existing variables removes the issue and
-- allows for *only* variables in the given character's dictionary to be modified.
-- However, you can't assign the variable to itself to prevent this issue
-- from occurring which makes this information pointless. So *this*
-- will stop it from assigning variables in other characters' dictionaries...
attributesCharacter["Server"] = {}
attributesCharacter["Server"]["NewVariable"] = "Value"
-- but this won't. (Because why would it?)
attributesCharacter["Server"] = attributesCharacter["Server"]
attributesCharacter["Server"]["NewVariable"] = "Value"
--]]
end)
-- After the event is called with "player1" as the argument,
-- "attributesModule" is equal to what's shown below.
attributesModule = {
character1 = {
Client = {...},
Server = {
NewVariable = "Value",
...,
},
Tester = {
NewVariable = "Value",
},
},
character2 = {
Client = {...},
Server = {
NewVariable = "Value",
...,
},
},
...,
}
-- For clarity, the new dictionary "Tester" and the new variable "NewVariable"
-- should only be present in "character1". However, "NewVariable" appears
-- within "character2" and every other characters' dictionary that follows.
I looked throughout the Roblox Studio forum and was unable to find anyone else with an issue like mine, so I decided to make this post.
I am new to posting in this forum, so I apologize if I’ve done something wrong or was unable to describe the issue well enough. If any other information is needed, please be sure to inform me.
I’d appreciate any kind of help since this technical issue has been bugging me for several hours.
Thank you.


