Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Main.lua - Modified 12/14/2024
- --// Services
- local JukeboxConfig = require(script.Parent)
- local MarketplaceService = game:GetService("MarketplaceService")
- local DataStoreService = game:GetService("DataStoreService")
- local AsyncAdminCore = game:GetService("ServerScriptService"):WaitForChild("AsyncAdminCore")
- AsyncAdminCore = require(AsyncAdminCore)
- --// Globals
- local Model = JukeboxConfig.Model
- local Endpoint = Instance.new("RemoteFunction", game:GetService("ReplicatedStorage"))
- local RemoteEndpoint = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
- local PlayerSound = {}
- --// Blacklist Handling
- -- Temporary solution, global variable.
- local SoundBlacklist : table
- local SoundLogs : table = {}
- local JukeBoxData = DataStoreService:GetDataStore("JukeBoxData V2")
- local Success, Error = pcall(function()
- SoundBlacklist = JukeBoxData:GetAsync("Blacklist")
- if not SoundBlacklist then
- warn("New sound blacklist!")
- SoundBlacklist = {1846272009, 6680431093}
- end
- end)
- if not Success then
- warn("Jukebox blacklist failed to load!")
- _G.SoundBlacklist = {}
- end
- --// Handle Logs
- function AddLog(Log : string)
- table.insert(SoundLogs, Log)
- if #SoundLogs > 100 then
- table.remove(SoundLogs, 1)
- end
- end
- --// Create Endpoint
- Endpoint.Name = "JukeBoxEndpoint"
- RemoteEndpoint.Name = "RemoteJukeBoxEndpoint"
- --// Handle Client
- function HandleClient(Client)
- --> Assert Permission
- if JukeboxConfig.GamepassID and (not MarketplaceService:UserOwnsGamePassAsync(Client.UserId, JukeboxConfig.GamepassID)) then
- return
- end
- local function handleCharacter()
- local newTool = Model:Clone()
- newTool.Parent = Client.Backpack
- newTool.Unequipped:Connect(function()
- if PlayerSound[Client] then
- PlayerSound[Client].Playing = false
- end
- end)
- newTool.Equipped:Connect(function()
- if PlayerSound[Client] then
- PlayerSound[Client].Playing = true
- end
- end)
- end
- repeat wait() until Client.Character
- handleCharacter()
- Client.CharacterAdded:Connect(handleCharacter)
- end
- -- Onload Players
- for _, v in ipairs(game.Players:GetPlayers()) do
- coroutine.wrap(HandleClient)(v)
- end
- game.Players.PlayerAdded:Connect(HandleClient)
- Endpoint.OnServerInvoke = (function(Player, Request, Payload)
- if Request == "SetSound" then
- if not Payload then
- return
- end
- Payload = tonumber(Payload)
- if not Payload then
- return
- end
- if PlayerSound[Player] then
- PlayerSound[Player]:Stop()
- PlayerSound[Player]:Destroy()
- end
- --- Validate Blacklist
- if table.find(SoundBlacklist, Payload) then
- AddLog(Player.Name.." X "..Payload)
- AsyncAdminCore.Modules.API.PromptGui(Player, "Notification", {
- ["Title"] = "Sound Blocked!";
- ["Content"] = "This Sound ID is disallowed.";
- })
- return false
- end
- local JukeBox = Player.Character:FindFirstChild(Model.Name)
- local Speaker = Instance.new("Sound", JukeBox.Handle)
- Speaker.SoundId = "rbxassetid://"..Payload
- Speaker.Volume = 0
- Speaker.Playing = true
- PlayerSound[Player] = Speaker
- RemoteEndpoint:FireAllClients({Player, Speaker})
- AddLog(Player.Name.." ✓ "..Payload)
- return Speaker
- elseif Request == "Pause" then
- if PlayerSound[Player] then
- local Status = PlayerSound[Player].Playing
- Status = not Status
- PlayerSound[Player].Playing = Status
- return Status
- end
- else
- return PlayerSound
- end
- end)
- AsyncAdminCore.Modules.CommandHandler.RegisterCommandHolder("Jukebox Utilities", {
- {
- ["Name"] = "viewblacklist";
- ["Aliases"] = {};
- ["Permissions"] = {"Any", {
- {"Rank", 1};
- }};
- ["Arguments"] = {};
- ["Function"] = function(Session)
- AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Statistics", {
- Title = "Blacklist";
- Statistics = SoundBlacklist;
- })
- end;
- },
- {
- ["Name"] = "jukeboxlogs";
- ["Aliases"] = {"jblog", "jbl"};
- ["Permissions"] = {"Any", {
- {"Rank", 1};
- }};
- ["Arguments"] = {};
- ["Function"] = function(Session)
- print(Session)
- AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Statistics", {
- Title = "Jukebox Logs (Newest at bottom)";
- Statistics = SoundLogs;
- })
- end;
- },
- {
- ["Name"] = "removeblacklist";
- ["Aliases"] = {"delblacklist"};
- ["Permissions"] = {"Any", {
- {"Rank", 1};
- }};
- ["Arguments"] = {"Number"};
- ["Function"] = function(Session)
- local Position = table.find(SoundBlacklist, Session.Execution.Arguments[1])
- if Position then
- table.remove(SoundBlacklist, Position)
- else
- AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Notification", {
- ["Title"] = "Failed!";
- ["Content"] = "This Sound ID is not blacklisted.";
- })
- end
- end;
- },
- {
- ["Name"] = "addblacklist";
- ["Aliases"] = {"blacklistsound", "blacklistid"};
- ["Permissions"] = {"Any", {
- {"Rank", 1};
- }};
- ["Arguments"] = {"Number"};
- ["Function"] = function(Session)
- table.insert(SoundBlacklist, Session.Execution.Arguments[1])
- AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Notification", {
- ["Title"] = "Success!";
- ["Content"] = "Blacklisted the Sound ID.";
- })
- end;
- },
- {
- ["Name"] = "clearblacklist";
- ["Aliases"] = {};
- ["Permissions"] = {"Any", {
- {"Rank", 1};
- }};
- ["Arguments"] = {};
- ["Function"] = function(Session)
- SoundBlacklist = {}
- end;
- },
- {
- ["Name"] = "saveblacklist";
- ["Aliases"] = {};
- ["Permissions"] = {"Any", {
- {"Rank", 1};
- }};
- ["Arguments"] = {};
- ["Function"] = function(Session)
- JukeBoxData:SetAsync("Blacklist", SoundBlacklist)
- AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Notification", {
- ["Title"] = "Success!";
- ["Content"] = "New servers will recieve this blacklist.";
- })
- end;
- },
- })
Advertisement
Add Comment
Please, Sign In to add comment