When server is made u we’re suppose to join it but when I try it displays me an error which I’m unsure how to fix! Any way you can guys help me? Would be appriciated!
local base = script.Parent.Parent.Parent
base[“TrainingHub: Configuration”].Parent = base[“Items (Ignore)”][“TrainingHubStorage:Jugo”]
base[“Items (Ignore)”][“TrainingHubStorage:Jugo”].Parent = game.ReplicatedStorage
base[“Items (Ignore)”][“TrainingHubServer:Jugo”].Parent = game.ServerScriptService
base[“Items (Ignore)”][“TrainingHubUI:Jugo”].Parent = game.StarterGuilocal Config = require(game.ReplicatedStorage[“TrainingHubStorage:Jugo”][“TrainingHub: Configuration”])
local GroupIdentifier = Config.GroupId
local CreateSessionStaff = Config.Staff
local WebhookURL = Config.Webhooklocal TeleportService = game:GetService(“TeleportService”)
local HttpService = game:GetService(“HttpService”)
local CurrentPlaceId = 124750007132749
local RefreshInterval = 3
local FirebaseAPI = require(game.ReplicatedStorage[“TrainingHubStorage:Jugo”][“TrainingHub: Configuration”].ExternalDatastore)
local ReservedServersData = FirebaseAPI:GetFirebase(“Servers”)local function padNumber(num, length)
return string.format(“%0” … length … “i”, num)
endlocal function generateTimestamp()
local osDate = os.date(“!*t”)
local year, month, day = osDate[“year”], osDate[“month”], osDate[“day”]
local hour, minute, second = osDate[“hour”], osDate[“min”], osDate[“sec”]
return year … “-” … padNumber(month, 2) … “-” … padNumber(day, 2) … “T” … padNumber(hour, 2) … “:” … padNumber(minute, 2) … “:” … padNumber(second, 2) … “Z”
endlocal function determineServerType()
if game.PrivateServerId ~= “” then
if game.PrivateServerOwnerId ~= 0 then
return “VIPServer”
else
return “ReservedServer”
end
else
return “StandardServer”
end
endgame.Players.PlayerAdded:Connect(function(Player)
if determineServerType() == “ReservedServer” then
Player.PlayerGui:WaitForChild(“TrainingHubUI:Jugo”):Destroy()local ServerList = { game.HttpService:JSONDecode(ReservedServersData:GetAsync("ServerOne")), game.HttpService:JSONDecode(ReservedServersData:GetAsync("ServerTwo")), game.HttpService:JSONDecode(ReservedServersData:GetAsync("ServerThree")), } for idx, server in pairs(ServerList) do if game.PrivateServerId == server.ServerId then ReservedServersData:SetAsync("Server"..idx, game.HttpService:JSONEncode({ ServerCode = server.ServerCode, ServerId = server.ServerId, Creator = server.Creator, Host = server.Host, Time = server.Time, Players = #game.Players:GetPlayers() })) end end
end
end)game.Players.PlayerRemoving:Connect(function(Player)
if determineServerType() == “ReservedServer” then
local ServerList = {
game.HttpService:JSONDecode(ReservedServersData:GetAsync(“ServerOne”)),
game.HttpService:JSONDecode(ReservedServersData:GetAsync(“ServerTwo”)),
game.HttpService:JSONDecode(ReservedServersData:GetAsync(“ServerThree”)),
}for idx, server in pairs(ServerList) do if game.PrivateServerId == server.ServerId then ReservedServersData:SetAsync("Server"..idx, game.HttpService:JSONEncode({ ServerCode = server.ServerCode, ServerId = server.ServerId, Creator = server.Creator, Host = server.Host, Time = server.Time, Players = #game.Players:GetPlayers() })) end end
end
end)game.ReplicatedStorage[“TrainingHubStorage:Jugo”].Events.CreateTraining.OnServerEvent:Connect(function(Plr, sessionData)
if Plr:GetRankInGroup(GroupIdentifier) >= CreateSessionStaff then
if determineServerType() ~= “ReservedServer” then
local ReservedServerCode, PrivateServerId = TeleportService:ReserveServer(game.PlaceId)
ReservedServersData:SetAsync(“Server”…sessionData.Server, game.HttpService:JSONEncode({
ServerCode = ReservedServerCode,
ServerId = PrivateServerId,
Creator = Plr.UserId,
Host = sessionData.Host,
Time = sessionData.Time,
Players = 0
}))local discordMessage = { ["embeds"] = { { ["author"] = { ["name"] = Plr.Name, ["icon_url"] = "https://api.newstargeted.com/roblox/users/v1/avatar-headshot?userid="..tostring(Plr.UserId).."&size=150x150&format=Png&isCircular=false" }, ["title"] = "**Training Reserved! 🎉**", ["description"] = "A new training session has been successfully reserved!", ["fields"] = { { ["name"] = "**Server Number**", ["value"] = "`" .. sessionData.Server .. "`", ["inline"] = false }, { ["name"] = "**Host**", ["value"] = "**" .. Plr.Name .. "** (`" .. tostring(Plr.UserId) .. "`)", ["inline"] = false }, { ["name"] = "**Training Time**", ["value"] = "`" .. sessionData.Time .. "`", ["inline"] = false } }, ["color"] = 0x000000, ["footer"] = { ["text"] = "TrainingHub", }, ["timestamp"] = generateTimestamp(), } } } local jsonPayload = HttpService:JSONEncode(discordMessage) local success, errorMessage = pcall(function() HttpService:PostAsync(WebhookURL, jsonPayload) end) if not success then warn("Failed to send Discord webhook:", errorMessage) end end
end
end)game.ReplicatedStorage[“TrainingHubStorage:Jugo”].Events.JoinTraining.OnServerEvent:Connect(function(Plr, ReservedServerCode)
if determineServerType() ~= “ReservedServer” then
TeleportService:TeleportToPrivateServer(CurrentPlaceId, ReservedServerCode, {Plr})
end
end)game.ReplicatedStorage[“TrainingHubStorage:Jugo”].Events.RemoveTraining.OnServerEvent:Connect(function(player, serverIndex)
if not serverIndex then
warn(“RemoveServer event triggered without a valid server number!”)
return
endif player:GetRankInGroup(GroupIdentifier) >= CreateSessionStaff and determineServerType() ~= “ReservedServer” then
local emptyServerData = {
ServerCode = “”,
ServerId = “”,
Creator = 0,
Host = “”,
Time = “”,
Players = 0
}
ReservedServersData:SetAsync(“Server” … tostring(serverIndex), game.HttpService:JSONEncode(emptyServerData))
end
end)while wait(RefreshInterval) do
if determineServerType() ~= “ReservedServer” then
local ServerList = {}for i = 1, 4 do local serverKey = "Server" .. i local serverData = ReservedServersData:GetAsync(serverKey) if serverData and serverData ~= "" then local success, decodedData = pcall(function() return game.HttpService:JSONDecode(serverData) end) if success then ServerList[i] = decodedData else warn("Failed to decode JSON for", serverKey, ":", decodedData) ServerList[i] = {ServerCode = "", ServerId = "", Creator = 0, Host = "", Time = "", Players = 0} end else ServerList[i] = {ServerCode = "", ServerId = "", Creator = 0, Host = "", Time = "", Players = 0} end end game.ReplicatedStorage["TrainingHubStorage:Jugo"].Events.DisplayServers:FireAllClients(ServerList)
end
end