2 Likes
Hey, it’s very simple.
Use this :PromptOptIn() to prompt the Turn on notifications,
and use :CanPromptOptInAsync() to check if the player is following the experience
- false means is following
- true means is not following here is a simple example
--// Services
local ExperienceNotificationService = game:GetService("ExperienceNotificationService")
--// Functions
-- Checks if the player is following the experience.
local function IsFollowingExperience(retries: number)
local IsFollowing
-- This yields so it requires a pcall in case of an error.
local Success = pcall(function()
IsFollowing = ExperienceNotificationService:CanPromptOptInAsync()
end)
-- Makes the retry process infinite if it's within the negatives.
if retries < 0 then
retries = math.huge
end
-- Retries the logic until it's successful.
while retries >= 1 do
-- Simple delay before trying again.
task.wait(1)
-- Deducts -1 from the retries.
retries -= 1
-- Tries to check if the player is following the experience again.
Success = pcall(function()
IsFollowing = ExperienceNotificationService:CanPromptOptInAsync()
end)
if Success then break end
end
-- If it was a failure then return that the player isn't following the experience.
if not Success then
return false
end
-- returns if the player is following the experience the reason.
-- why i've added not is because if it's true it means the player isn't following the experience.
-- but if it's false it means the player is indeed following the experience.
return not IsFollowing
end
--// Logic
-- Checks if the player is following the experience.
local IsFollowing = IsFollowingExperience(3)
-- Checks if the player isn't following the experience.
if not IsFollowing then
-- This handles prompt the notification prompt for following the game.
ExperienceNotificationService:PromptOptIn()
else
warn("Already following experience!")
end
--// Connections
-- Listen to whenever a prompt is closed.
ExperienceNotificationService.OptInPromptClosed:Connect(function()
-- Checks if the player is following the experience.
local IsFollowing = IsFollowingExperience(3)
if IsFollowing then
-- if he followed the experience.
warn("Player has followed the experience.")
else
-- if he cancelled and didn't follow the experience.
warn("Player refused to follow the experience.")
end
end)
- Client side only, you will have to make a client/server communication to check. I’m not sure if there is any way to check that directly on the server, correct me if I’m wrong.
3 Likes