Script problem!

  1. What do you want to achieve?
    I want this script work XD
  2. What is the issue?
    My var NewServerList return nil !
  3. What solutions have you tried so far?
local RemoteEvent = game:GetService("ReplicatedStorage").ServerInfo
local DataStoreService = game:GetService("DataStoreService")
local ServerList = DataStoreService:GetDataStore("ServerList")

RemoteEvent.OnServerEvent:Connect(function(Player, ServerInfo)
	if ServerList:GetAsync(Player.UserId) == nil then
		ServerList:SetAsync(Player.UserId, {ServerInfo})
	else
		local NewServerList = table.insert(ServerList:GetAsync(Player.UserId), ServerInfo)
		ServerList:SetAsync(Player.UserId, NewServerList)
		print(ServerList:GetAsync(Player.UserId))
	end
end)
2 Likes

table.insert() doesnt return a table, it adds a value to an existing table

2 Likes

So how can I achieve what I want to do ?

replace that with

		local NewServerList = ServerList:GetAsync(Player.UserId)
		table.insert(NewServerList, ServerInfo)
		ServerList:SetAsync(Player.UserId, NewServerList)
		print(ServerList:GetAsync(Player.UserId))

Also next time please try and provide more information than I want this script work XD, and refer to Roblox Engine API Reference | Roblox Creator Documentation before making a post to see if you cant find your answer

2 Likes

NewServerList = ServerList:GetAsync(Player.UserId)

1 Like

Thank you very much and I will improve my explaination !

Thank you very much !!!
(efzee)