I have made this script which should save and load a table. When I leave the game it prints ("Hi") but when I join again it just prints blank text?

local Banlogs = {}
local uniquekey = 'serverid-1591857823878569034'

local DSService = game:GetService('DataStoreService'):GetDataStore('ThisisDaStoreTing')
game.Players.PlayerAdded:connect(function(plr)
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then 
		print(unpack(Banlogs))
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
	table.insert(Banlogs, "Hi")
	DSService:SetAsync(uniquekey, Banlogs)
	print(unpack(Banlogs))
end)

7 comments

0

Maybe try this in-game, not in studio? DataStore not works in studio

0

Same issue in game, I turned the Dataaccess for studio on aswell so it should work. But I am getting the same error in game

0

I know. That's because you joining another server everytime, and in the script's 1st line you are telling the script Banlogs is {}, so when a player joins, first thing is setting Banlogs to {}, so that's why it prints just a blank text. Maybe you should store it in an instance, e.g a stringvalue

0

Alright how can I load and store that?

0

ehm.. Watch alvinbloxx's video how he made a leaderboard script, you can do somehow like that, by putting a stringvalue into every player (at game.Players.Player) link: https://www.youtube.com/watch?v=tOOS9lMIYes

0

How can I convert a table into a string value and convert a string value into a table?

0

Converting a table to a string can be done two ways: first table.concat, second is unpack(), which not returns a string, but will show all elements in the table. And why do you want to convert A string value to a table? To add it into a table, use table.instert(table, element/value), but if you want to create a new table, do it, e.g table1 ={..}. Read about it, I don't exactly know what you want