MarketplaceService:GetUserSubscriptionStatusAsync
Returns a table that contains the subscription status of the user for the given subscriptionId. The table contains the following keys:
Key | Type | Description |
---|---|---|
IsSubscribed | boolean | True if the user's subscription is active. |
IsRenewing | boolean | True if the user is set to renew this subscription after the current subscription period ends. |
Note that IsSubscribed will be true only when a user has purchased the subscription and the payment has been successfully processed. If the payment for a user's initial subscription purchase is still processing or has failed, IsSubscribed returns false. To understand when a user's subscription status has changed, see the Players.UserSubscriptionStatusChanged event.
Parameters
The ID of the subscription to check for.
Returns
Code Samples
This code sample demonstrates how to check the subscription status of a user for a certain subscription. As a user enters the game, their account is checked for the status of that subscription and a message is printed.
Notice how the call to GetUserSubscriptionStatusAsync is wrapped in pcall - this prevents the code from throwing an error in case the user's subscription status can't be checked for some reason. Should such an error occur, the success variable would be false.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local subscriptionID = "EXP-00000"
local function checkSubStatus(player)
local subStatus = {}
local success, message = pcall(function()
-- returns IsRenewing and IsSubscribed
subStatus = MarketplaceService:GetUserSubscriptionStatusAsync(player, subscriptionID)
end)
if not success then
warn("Error while checking if player has subscription: " .. tostring(message))
return
end
if subStatus["IsSubscribed"] then
print(player.Name .. " is subscribed with " .. subscriptionID)
-- Give player permissions associated with the subscription
end
end
Players.PlayerAdded:Connect(checkSubStatus)