local PlayerData = {
["player1"] ={
}
}
local AllQuests = {
{
["Quests"] = 0
}
}
local randomQuest = math.random(#AllQuests)
local choosenQuest = AllQuests[1]--[randomQuest]
local ID = 1
PlayerData["player1"][1] = choosenQuest
PlayerData["player1"][1]["ID"] = 1
print(AllQuests)
This is what AllQuests prints as
My goal was to clone AllQuests’s format into PlayerData so that I can use it as a template to setup other quests, but it seems to connect the two. So whenever I edit AllQuests that that’s in PlayerData, its now editing it in the original AllQuests as well.
If you were to increase the value below in 10 different scripts simultaneously 10*10. value would become 100. Because all the scripts have access to the same table through a reference.
local t = {
value = 10
}
return t
What you want to do is table.clone(AllQuests[1]) to create a new table, where the elements of the previous table are given to the new table.
table.clone is a shallowcopy, it would work in this case, but if you had another table within allQuests[1], you’d need a deepcopy.
I recommend you to not learn luau as your first programming language. Because it won’t teach you things like objects (storage in RAM), compilers and interpreters until it’s too late.
Do you know what JIT stands for in the LuaJIT? JIT stands for just-in-time compiler, LuaJIT is a compiled and interpreted programming language.