Alexplazz

Untitled

Dec 16th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. -- Main.lua - Modified 12/14/2024
  2.  
  3. --// Services
  4. local JukeboxConfig = require(script.Parent)
  5. local MarketplaceService = game:GetService("MarketplaceService")
  6. local DataStoreService = game:GetService("DataStoreService")
  7. local AsyncAdminCore = game:GetService("ServerScriptService"):WaitForChild("AsyncAdminCore")
  8. AsyncAdminCore = require(AsyncAdminCore)
  9.  
  10.  
  11. --// Globals
  12. local Model = JukeboxConfig.Model
  13. local Endpoint = Instance.new("RemoteFunction", game:GetService("ReplicatedStorage"))
  14. local RemoteEndpoint = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
  15. local PlayerSound = {}
  16.  
  17. --// Blacklist Handling
  18. -- Temporary solution, global variable.
  19. local SoundBlacklist : table
  20. local SoundLogs : table = {}
  21.  
  22. local JukeBoxData = DataStoreService:GetDataStore("JukeBoxData V2")
  23. local Success, Error = pcall(function()
  24. SoundBlacklist = JukeBoxData:GetAsync("Blacklist")
  25. if not SoundBlacklist then
  26. warn("New sound blacklist!")
  27. SoundBlacklist = {1846272009, 6680431093}
  28. end
  29. end)
  30.  
  31. if not Success then
  32. warn("Jukebox blacklist failed to load!")
  33. _G.SoundBlacklist = {}
  34. end
  35.  
  36. --// Handle Logs
  37. function AddLog(Log : string)
  38. table.insert(SoundLogs, Log)
  39. if #SoundLogs > 100 then
  40. table.remove(SoundLogs, 1)
  41. end
  42. end
  43.  
  44. --// Create Endpoint
  45.  
  46. Endpoint.Name = "JukeBoxEndpoint"
  47. RemoteEndpoint.Name = "RemoteJukeBoxEndpoint"
  48.  
  49. --// Handle Client
  50. function HandleClient(Client)
  51. --> Assert Permission
  52. if JukeboxConfig.GamepassID and (not MarketplaceService:UserOwnsGamePassAsync(Client.UserId, JukeboxConfig.GamepassID)) then
  53. return
  54. end
  55.  
  56. local function handleCharacter()
  57. local newTool = Model:Clone()
  58. newTool.Parent = Client.Backpack
  59.  
  60. newTool.Unequipped:Connect(function()
  61. if PlayerSound[Client] then
  62. PlayerSound[Client].Playing = false
  63. end
  64. end)
  65.  
  66. newTool.Equipped:Connect(function()
  67. if PlayerSound[Client] then
  68. PlayerSound[Client].Playing = true
  69. end
  70. end)
  71. end
  72.  
  73. repeat wait() until Client.Character
  74. handleCharacter()
  75.  
  76. Client.CharacterAdded:Connect(handleCharacter)
  77.  
  78. end
  79.  
  80. -- Onload Players
  81. for _, v in ipairs(game.Players:GetPlayers()) do
  82. coroutine.wrap(HandleClient)(v)
  83. end
  84. game.Players.PlayerAdded:Connect(HandleClient)
  85.  
  86. Endpoint.OnServerInvoke = (function(Player, Request, Payload)
  87. if Request == "SetSound" then
  88. if not Payload then
  89. return
  90. end
  91.  
  92. Payload = tonumber(Payload)
  93. if not Payload then
  94. return
  95. end
  96.  
  97. if PlayerSound[Player] then
  98. PlayerSound[Player]:Stop()
  99. PlayerSound[Player]:Destroy()
  100. end
  101.  
  102. --- Validate Blacklist
  103. if table.find(SoundBlacklist, Payload) then
  104. AddLog(Player.Name.." X "..Payload)
  105. AsyncAdminCore.Modules.API.PromptGui(Player, "Notification", {
  106. ["Title"] = "Sound Blocked!";
  107. ["Content"] = "This Sound ID is disallowed.";
  108. })
  109. return false
  110. end
  111.  
  112. local JukeBox = Player.Character:FindFirstChild(Model.Name)
  113. local Speaker = Instance.new("Sound", JukeBox.Handle)
  114. Speaker.SoundId = "rbxassetid://"..Payload
  115. Speaker.Volume = 0
  116. Speaker.Playing = true
  117.  
  118. PlayerSound[Player] = Speaker
  119. RemoteEndpoint:FireAllClients({Player, Speaker})
  120. AddLog(Player.Name.." ✓ "..Payload)
  121. return Speaker
  122. elseif Request == "Pause" then
  123. if PlayerSound[Player] then
  124. local Status = PlayerSound[Player].Playing
  125. Status = not Status
  126. PlayerSound[Player].Playing = Status
  127. return Status
  128. end
  129. else
  130. return PlayerSound
  131. end
  132. end)
  133.  
  134. AsyncAdminCore.Modules.CommandHandler.RegisterCommandHolder("Jukebox Utilities", {
  135. {
  136. ["Name"] = "viewblacklist";
  137. ["Aliases"] = {};
  138. ["Permissions"] = {"Any", {
  139. {"Rank", 1};
  140. }};
  141. ["Arguments"] = {};
  142. ["Function"] = function(Session)
  143. AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Statistics", {
  144. Title = "Blacklist";
  145. Statistics = SoundBlacklist;
  146. })
  147. end;
  148. },
  149.  
  150. {
  151. ["Name"] = "jukeboxlogs";
  152. ["Aliases"] = {"jblog", "jbl"};
  153. ["Permissions"] = {"Any", {
  154. {"Rank", 1};
  155. }};
  156. ["Arguments"] = {};
  157. ["Function"] = function(Session)
  158. print(Session)
  159. AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Statistics", {
  160. Title = "Jukebox Logs (Newest at bottom)";
  161. Statistics = SoundLogs;
  162. })
  163. end;
  164. },
  165.  
  166. {
  167. ["Name"] = "removeblacklist";
  168. ["Aliases"] = {"delblacklist"};
  169. ["Permissions"] = {"Any", {
  170. {"Rank", 1};
  171. }};
  172. ["Arguments"] = {"Number"};
  173. ["Function"] = function(Session)
  174. local Position = table.find(SoundBlacklist, Session.Execution.Arguments[1])
  175. if Position then
  176. table.remove(SoundBlacklist, Position)
  177. else
  178. AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Notification", {
  179. ["Title"] = "Failed!";
  180. ["Content"] = "This Sound ID is not blacklisted.";
  181. })
  182. end
  183. end;
  184. },
  185.  
  186. {
  187. ["Name"] = "addblacklist";
  188. ["Aliases"] = {"blacklistsound", "blacklistid"};
  189. ["Permissions"] = {"Any", {
  190. {"Rank", 1};
  191. }};
  192. ["Arguments"] = {"Number"};
  193. ["Function"] = function(Session)
  194. table.insert(SoundBlacklist, Session.Execution.Arguments[1])
  195. AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Notification", {
  196. ["Title"] = "Success!";
  197. ["Content"] = "Blacklisted the Sound ID.";
  198. })
  199. end;
  200. },
  201.  
  202. {
  203. ["Name"] = "clearblacklist";
  204. ["Aliases"] = {};
  205. ["Permissions"] = {"Any", {
  206. {"Rank", 1};
  207. }};
  208. ["Arguments"] = {};
  209. ["Function"] = function(Session)
  210. SoundBlacklist = {}
  211. end;
  212. },
  213.  
  214. {
  215. ["Name"] = "saveblacklist";
  216. ["Aliases"] = {};
  217. ["Permissions"] = {"Any", {
  218. {"Rank", 1};
  219. }};
  220. ["Arguments"] = {};
  221. ["Function"] = function(Session)
  222. JukeBoxData:SetAsync("Blacklist", SoundBlacklist)
  223. AsyncAdminCore.Modules.API.PromptGui(Session.Player.Client, "Notification", {
  224. ["Title"] = "Success!";
  225. ["Content"] = "New servers will recieve this blacklist.";
  226. })
  227. end;
  228. },
  229. })
Advertisement
Add Comment
Please, Sign In to add comment