I think something's wrong with my code

So here is my code:

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("TimeFirstJoined#Test1")

local tagsTable = {}

local tags = game.ReplicatedStorage.Tags
local nameTag = tags.NameTag
local title = tags.TItle
local owner = tags.Owner

local function addTag(object, plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	if char then
		local head = char:WaitForChild("Head")
		if head then
			object:Clone().Parent = head
		end
	end
end

local function adjustTags(tagToAdd)
	table.insert(tagsTable, tagToAdd)
	local count = 0
	for _, object in pairs(tagsTable) do
		count = count + 1
		local ypos = 3.15 + ((count - 1) * 0.5)
		object.StudsOffset = Vector3.new(0, ypos, 0)
		print("+SUCCESS+")
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	addTag(nameTag, plr)
	
	if plr.UserId == 1003594243 then
		addTag(owner, plr)
		adjustTags(owner)
	end
	--
	local data = dataStore:GetAsync(plr.UserId)
	
	if not data then
		dataStore:SetAsync(plr.UserId, os.time())
		
		wait(1)
		data = dataStore:GetAsync(plr.UserId)
		
		local START = os.time {year = 2020; month = 6; day = 20}

		if data <= START then
   			print(plr.Name.." joined before Summer 2020")
			addTag(title, plr)
			adjustTags(title)
		end
	elseif data then
		local START = os.time {year = 2020; month = 6; day = 20}

		if data <= START then
   			print(plr.Name.." joined before Summer 2020")
			addTag(title, plr)
			adjustTags(title)
		end
	end
end)

And the player’s tags are adjusted. Well… this is a server script and I suddenly thought: “Wait, will the table will change for each player, or just one player?” So that’s why I came here. If that is so… that the table will change for each player, then how would I fix that?

so right after your player added event, you’d want to add

tagsTable[plr] = {}

and then replace the other things accordingly.
that may mean adding an extra argument to your adjustTags function tho so you can grab the player’s tagTable

2 Likes