Custom Private Server System Scripting Help

Hello! I am currently in the process of making a Custom Private Server System for an upcoming roleplay game that I am currently making. I used a YouTube Tutorial on how to make the custom private server system, And when I went to test everything out, There was an error that was shown for the script that handles the Private Server System on the games Server Side.

Wondering if anyone could help me out with fixing the issue.

Error Printed:

Line of Code:

ServerInfo DataStore:

local ServerInfo = DataStoreService:GetDataStore("ServerInformation")

The last line is where the issue is. (Getting the name of the Private Server)

local ServerInfoDictionary = ServerInfo:GetAsync(v.key)
local ServerItemTemplate = script.Parent:WaitForChild("ServerItem"):Clone()
		
ServerItemTemplate.Parent = Menu.ListedServers.Content.ScrollingFrame
ServerItemTemplate.PlayerCount.Text = v.value .."/15"
ServerItemTemplate.ServerName.Text = ServerInfoDictionary.ServerName

You should check if there is any data in the ServerInfoDictionary before trying to get it.

if ServerInfoDictionary ~= nil then
    --code here if there is info
else
    --code here if it does not exist (such as return)
end

because the player will not have any data if it’s their first time playing

So something like this?

if ServerInfoDictionary ~= nil then
	ServerItemTemplate.Parent = Menu.ListedServers.Content.ScrollingFrame
	ServerItemTemplate.PlayerCount.Text = v.value .."/15"
	ServerItemTemplate.ServerName.Text = ServerInfoDictionary.ServerName
else
	print("Player does not own any Private Servers")
	return
end
1 Like

yeah ig

or whatever you want lol

Do this instead as it is better and cleaner (guard clauses)

if serverinfodict == nil then

end

-- code that assumes it is not nil.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.