Advertisement
Cakey3101

Favourite Client

May 15th, 2025
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local AvatarEditorService = game:GetService("AvatarEditorService")
  4.  
  5. local Remotes = ReplicatedStorage.Remotes
  6.  
  7. local Player = Players.LocalPlayer
  8. local PlayerGui = Player.PlayerGui
  9.  
  10. local Gui = PlayerGui:WaitForChild("FavouriteUI")
  11. local Button = Gui.Button
  12.  
  13. local AlreadyRecieved = false
  14.  
  15. local GAME_ID = game.PlaceId
  16. local AVATAR_ITEM_TYPE = Enum.AvatarItemType.Asset
  17.  
  18. local function HasInventoryAccess()
  19.     local Success, Permission = pcall(function()
  20.         return AvatarEditorService:PromptAllowInventoryReadAccess()
  21.     end)
  22.    
  23.     return Success and Permission
  24. end
  25.  
  26. local function CheckFavourite()
  27.     if not HasInventoryAccess() then
  28.         warn("Cannot Read Player's Inventory Due To Privacy Reasons")
  29.         return false
  30.     end
  31.    
  32.     local Success, Favourited = pcall(function()
  33.         return AvatarEditorService:GetFavorite(GAME_ID, AVATAR_ITEM_TYPE)
  34.     end)
  35.    
  36.     if not Success then
  37.         warn("Failed To Check If Favourited")
  38.     end
  39.    
  40.     return Favourited
  41. end
  42.  
  43. local function PromptFavourite()
  44.     pcall(function()
  45.         AvatarEditorService:PromptSetFavorite(GAME_ID, AVATAR_ITEM_TYPE, true)
  46.     end)
  47. end
  48.  
  49. local function ButtonClicked()
  50.     if CheckFavourite() or AlreadyRecieved then return end
  51.    
  52.     PromptFavourite()
  53. end
  54.  
  55. local function PromptSetFavouriteCompleted(Result: Enum.AvatarPromptResult)
  56.     if Result ~= Enum.AvatarPromptResult.PermissionDenied and not AlreadyRecieved then
  57.         AlreadyRecieved = true
  58.         Remotes.GameFavourited:FireServer()
  59.     end
  60. end
  61.  
  62. Button.MouseButton1Click:Connect(ButtonClicked)
  63. AvatarEditorService.PromptSetFavoriteCompleted:Connect(PromptSetFavouriteCompleted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement