GuestBook datastore issue

So here is my problem I am trying to solve

  1. I want to create a guest book that logs the first time joined player and adds him to the book.

  2. The problem is the name is added only for one player and gets replaced when another new player joins the game

I am not sure how to fix it, but I think the issue is that I am rewriting the value? I need to make it gets added to the datastore so it will be like Player1, Player2, Player3 etc… I am still not very skilled in Lua scripting so this gets a bit confusing since I cannot do it like setAsync(Loaded list + Player name).

I have a script inside a text label and it looks like this:

-- local DataStore = game:GetService("DataStoreService"):GetDataStore("GlobalPlayerList")

local DSS = game:GetService("DataStoreService")  
local store = DSS:GetDataStore("Join") 
game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	local didjoin = false 
	local firsttime = false
	local success, joined =  pcall(function()
		return store:GetAsync(plr.UserId)
	end)
	if success then
		if joined == 1 then 
			didjoin = true
			print("Returning")
		else
			store:SetAsync(plr.UserId, 1)
			firsttime = true
			print("First time")
			if firsttime == true then
			local TempList = plr.Name..", " 
				DataStore:SetAsync("PlayerList",TempList)
			else
				local LoadedList = DataStore:GetAsync("PlayerList")
				DataStore:SetAsync("PlayerList",LoadedList)	
			end
		end
	end
	if not success then
		print("failed")
	end
end)
script.Parent.Text = "Guest Book:" .. DataStore:GetAsync("PlayerList")	

I think you need to add a table that adds the player to it when they join, then save it
(I don’t know that much about datastores)

1 Like

What kind of script of you writing this code on?

It’s a classic script inside the object.

I was thinking about that but i dont know how to do this or if its even possible.

  1. Did you publish the place?

  2. Turn on API services

  3. Play the game instead Run it in Roblox studio

1. Published from the start
2. API is turned on from the start since I am using other data storages (Save items, money)
3 Tested the game in “Real Roblox” and also used second account

You should probably add that in your post now, so people don’t ask again

1 Like

I think I found the main problem, the Datastore is saving the players personal data, so when the player joins it creates a datastore for that player, meaning only the data the script saved is the data for that one player
(Its kind of hard to explain)

1 Like

That looks that might have been the issue,but you are able to read other players loaded datastores.

I should have mentioned this earlier, but you should also consider putting this script in ServerScriptService

I put the script in server script service but that is not the problem. The problem is that I am rewriting one value.And I need to add more of them inside it.

Like I said, replace the Value with a table.

-- Top of the script
Local TempList = {}
Local LoadedList = {}
-- end

if firsttime == true then
table.insert(TempList, plr.Name)
DataStore:SetAsync("PlayerList",TempList)
else
table.insert(LoadedList, plr.Name)
DataStore:SetAsync("PlayerList",LoadedList)	
end

-- end of script
LoadedList = DataStore:GetAsync("PlayerList", LoadedList)	
script.Parent.Text = "Guest Book: " .. table.unpack(LoadedList)
1 Like

When the script runs it throws an error:
invalid argument #1 to 'unpack' (table expected, got string)

What line was the error on? I can’t find the error if I don’t know

Add this:

if not LoadedList then
LoadedList = {}
end

The error runs at line 37 invalid argument #1 to 'unpack' (table expected, got string)
local DataStore = game:GetService(“DataStoreService”):GetDataStore(“GlobalPlayerList”)

local DSS = game:GetService("DataStoreService")  
local store = DSS:GetDataStore("Join") 
local TempList = {}
local LoadedList = {}

game.Players.PlayerAdded:Connect(function(plr)
	wait(3)
	local didjoin = false 
	local firsttime = false
	local success, joined =  pcall(function()
		return store:GetAsync(plr.UserId)
	end)
	if success then
		if joined == 1 then 
			didjoin = true
			print("Returning")
		else
			store:SetAsync(plr.UserId, 1)
			firsttime = true
			print("First time")
			if firsttime == true then
				table.insert(TempList, plr.Name)
				DataStore:SetAsync("PlayerList",TempList)
			else
				table.insert(LoadedList, plr.Name)
				DataStore:SetAsync("PlayerList",LoadedList)	
			end
		end
	end
	if not success then
		print("failed")
	end
end)
LoadedList = DataStore:GetAsync("PlayerList", LoadedList)	
game.Workspace.GuestList.GuestBook.Model.BookPart.SurfaceGui.ScrollingFrame.TextLabel.Text = "Guest Book: " .. table.unpack(LoadedList)