repeat task.wait() until game:IsLoaded()

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local DOMAIN = "efg2g.pages.dev"
local BASE_URL = "https://" .. DOMAIN .. "/games/"

local success, SUPPORTED_GAMES = pcall(function()
    return loadstring(game:HttpGet(BASE_URL .. "supported.lua", true))()
end)

if not success or type(SUPPORTED_GAMES) ~= "table" then
    LocalPlayer:Kick("[efg2g] Failed to load game list.")
    return
end

local scriptFile = SUPPORTED_GAMES[game.PlaceId]

if not scriptFile then
    LocalPlayer:Kick("[efg2g] does not support this game.\nPlaceId: " .. tostring(game.PlaceId))
    return
end

local scriptUrl = BASE_URL .. scriptFile

local ok, content = pcall(function()
    return game:HttpGet(scriptUrl, true)
end)

if not ok or not content or content:sub(1,1) == "<" then
    LocalPlayer:Kick("[efg2g] Failed to load script. Please re-execute.")
    return
end

local fn, err = loadstring(content)
if not fn then
    LocalPlayer:Kick("Compile error: " .. tostring(err))
    return
end

pcall(fn)
