-
What do you want to achieve? Keep it simple and clear!
I want to achieve a system that checks if a ReservedServer has 1 or more players, else if it does not shut the server down -
What is the issue? Include screenshots / videos if possible!
Issue is idk where to start -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried a while true loop, didn’t work I checked the developer hub.
Here is the code I have got. Help would be appreciated
local DataStoreService = game:GetService("DataStoreService")
local GlobalDataStore = DataStoreService:GetGlobalDataStore()
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local function addServer(accessCode)
local success, data =
pcall(
function()
return GlobalDataStore:GetAsync("GlobalServerList") or {}
end
)
if success then
table.insert(data, accessCode)
local writeSuccess =
pcall(
function()
GlobalDataStore:SetAsync("GlobalServerList", data)
end
)
end
end
local function getServers()
local success, servers =
pcall(
function()
return GlobalDataStore:GetAsync("GlobalServerList")
end
)
if success then
return servers
end
end
local function removeServer(accessCode)
local success, data =
pcall(
function()
return GlobalDataStore:GetAsync("GlobalServerList") or {}
end
)
if success then
table.remove(data, accessCode)
local writeSuccess =
pcall(
function()
GlobalDataStore:SetAsync("GlobalServerList", data)
end
)
end
end
game.ReplicatedStorage.Events.CreateServer.OnServerEvent:Connect(
function(plr, arg, group)
TS:ReserveServer(game.PlaceId)
addServer(plr.Name)
for i, v in ipairs(getServers()) do
game.ReplicatedStorage.Events.UpdateList:FireAllClients(v)
end
end
)