Service · inherits Instance
AdService
The service responsible for in-experience advertising.
About AdService
AdService is responsible for in-experience advertising. This includes
rewarded video and
ad integrations.
Methods 7
CreateAdRewardFromDevProductId
(devProductId: int64) → AdRewardCreates anAdRewardto give users who watch a video ad.Constructs an
AdRewardthat wraps the given developer product so it can be passed toShowRewardedVideoAdAsync. When the user watches the entire rewarded video ad, the developer product identified bydevProductIdis granted through theProcessReceiptcallback with aProductPurchaseChannelofProductPurchaseChannel.AdReward.GetAdAvailabilityNowAsync
(adFormat: AdFormat) → GetAdAvailabilityNowResultYieldsChecks if an ad with the specified format is available to be shown to theLocalPlayer.This method may only be called from a
ScriptwithRunContext.Client.Note that you should call this method as close as possible to the moment you plan to show the ad. For example, if you have a "Watch video ad to get a reward" button in a shop menu, only call this method when the user opens the shop menu. This approach improves performance by preventing ads from unnecessarily being held in memory, and it benefits CPM (cost-per-thousand impressions) and earnings by optimizing the ad fill rate.
GetCampaignEligibilityAsync
(campaignId: string, player: Player? = nil) → GetCampaignEligibilityResultYieldsChecks aPlayer's eligibility to be shown an ad integration campaign.GetCampaignEligibilityAsyncchecks whether aPlayeris eligible to be shown a specific ad integration campaign, returning a dictionary that looks like{ IsEligible: boolean }.Call this method and confirm that
result.IsEligibleistruebefore you display any of the campaign's ad integration assets or register their disclosure buttons withRegisterDisclosureButton. All ad integration assets should remain hidden until thePlayeris confirmed eligible.When called from the client, the
playerargument defaults to theLocalPlayer. When called from the server,playeris required. The call raises an error if the suppliedcampaignIdexceeds the maximum allowed length.RegisterAdOpportunityAsync
(instance: Instance, placementId: int64?) → ()YieldsTracks how many times a user had the chance to watch a video ad and the rate at which they actually watched the ad.This method may only be called from a
ScriptwithRunContext.Client.Registers a
GuiButtonfor ad opportunity tracking. Once registered, the system periodically checks whether the button is visible and unobstructed (the topmost input-sinking element at its center point). These visibility transitions are reported as ad opportunity impressions and used to measure the rate at which users are presented with, and choose to watch, rewarded video ads.The
instancemust be aGuiButtonthat is a descendant of aScreenGuiunderPlayerGui. If the instance is moved out of a valid hierarchy at runtime, tracking pauses automatically and resumes when it returns to a valid ancestor. CallUnregisterAdOpportunityto stop tracking the instance.RegisterDisclosureButton
(disclosureButton: GuiButton, adIntegrationPlacementId: string) → ()Registers an ad disclosure button for an ad integration.This method may only be called from a
ScriptwithRunContext.Client.RegisterDisclosureButtonmarks a button in your experience as an ad disclosure for an ad integration. When a user clicks it, they can see who is paying for the ad. See ad integrations for guidance on what the disclosures should look like and when they should be visible.Note: you must verify that the
LocalPlayeris eligible to see the associated ad integration campaign by callingGetCampaignEligibilityAsyncand verifying thatresult.IsEligibleistruebefore attempting to register a disclosure button for it. If you do not wait, or theLocalPlayeris not eligible to see the associated campaign, thenRegisterDisclosureButtonwill raise an error.ShowRewardedVideoAdAsync
(player: Player, reward: AdReward, placementId: int64?) → ShowAdResultYieldsPlays the video ad to the current user inside the experience.Warning: Rewarded Video ads must be user opt-in and clearly disclosed. For details, review our eligibility requirements and advertising standards.
This method may only be called from a
ScriptwithRunContext.Server.Note: before calling this method, you must first verify that the specified user has a rewarded video ad available to show by calling
GetAdAvailabilityNowAsync. If the client does not have an available ad, thenShowRewardedVideoAdAsyncwill returnShowAdResult.AdNotReady.UnregisterAdOpportunity
(instance: Instance) → ()Stops tracking an instance that was previously registered withRegisterAdOpportunityAsync.Removes
instancefrom the ad opportunity tracker so that it no longer counts toward the rewarded video ad opportunity reporting started byRegisterAdOpportunityAsync(). Call it once an instance should no longer be treated as an ad opportunity, such as when its associated UI is closed or removed.If the supplied
instanceis not currently being tracked, this method has no effect.
AdService also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.