I want to create a guest book that logs the first time joined player and adds him to the book.
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")
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
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)
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.
-- 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)
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)