Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local AvatarEditorService = game:GetService("AvatarEditorService")
- local Remotes = ReplicatedStorage.Remotes
- local Player = Players.LocalPlayer
- local PlayerGui = Player.PlayerGui
- local Gui = PlayerGui:WaitForChild("FavouriteUI")
- local Button = Gui.Button
- local AlreadyRecieved = false
- local GAME_ID = game.PlaceId
- local AVATAR_ITEM_TYPE = Enum.AvatarItemType.Asset
- local function HasInventoryAccess()
- local Success, Permission = pcall(function()
- return AvatarEditorService:PromptAllowInventoryReadAccess()
- end)
- return Success and Permission
- end
- local function CheckFavourite()
- if not HasInventoryAccess() then
- warn("Cannot Read Player's Inventory Due To Privacy Reasons")
- return false
- end
- local Success, Favourited = pcall(function()
- return AvatarEditorService:GetFavorite(GAME_ID, AVATAR_ITEM_TYPE)
- end)
- if not Success then
- warn("Failed To Check If Favourited")
- end
- return Favourited
- end
- local function PromptFavourite()
- pcall(function()
- AvatarEditorService:PromptSetFavorite(GAME_ID, AVATAR_ITEM_TYPE, true)
- end)
- end
- local function ButtonClicked()
- if CheckFavourite() or AlreadyRecieved then return end
- PromptFavourite()
- end
- local function PromptSetFavouriteCompleted(Result: Enum.AvatarPromptResult)
- if Result ~= Enum.AvatarPromptResult.PermissionDenied and not AlreadyRecieved then
- AlreadyRecieved = true
- Remotes.GameFavourited:FireServer()
- end
- end
- Button.MouseButton1Click:Connect(ButtonClicked)
- AvatarEditorService.PromptSetFavoriteCompleted:Connect(PromptSetFavouriteCompleted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement