-- [[ UNIVERSAL GAME MANAGER ]] -- Features: Auto-Saving DataStore, Leaderboard, and Admin Commands -- Instructions: Place this in ServerScriptService local DataStoreService = game:GetService("DataStoreService") local PlayerData = DataStoreService:GetDataStore("GlobalPlayerData_V1") local Players = game:GetService("Players") -- SETTINGS local ADMIN_USER_IDS = {000000} -- Replace 000000 with your Roblox ID to use admin commands local STARTING_COINS = 100 -- [[ LEADERBOARD & DATA LOADING ]] Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Parent = leaderstats -- Load Data local success, savedData = pcall(function() return PlayerData:GetAsync(tostring(player.UserId)) end) if success and savedData then coins.Value = savedData else coins.Value = STARTING_COINS end -- [[ ADMIN COMMANDS ]] player.Chatted:Connect(function(message) local isAdmin = false for _, id in pairs(ADMIN_USER_IDS) do if player.UserId == id then isAdmin = true break end end if isAdmin then local args = string.split(message, " ") -- Command: /give [amount] if args[1] == "/give" and args[2] then coins.Value = coins.Value + tonumber(args[2]) print("Admin added " .. args[2] .. " coins to " .. player.Name) end -- Command: /reset if args[1] == "/reset" then coins.Value = 0 end end end) end) -- [[ DATA SAVING ]] local function save(player) local success, err = pcall(function() PlayerData:SetAsync(tostring(player.UserId), player.leaderstats.Coins.Value) end) if not success then warn("Could not save data for " .. player.Name .. ": " .. err) end end Players.PlayerRemoving:Connect(save) game:BindToClose(function() for _, player in pairs(Players:GetPlayers()) do save(player) end end)