So basically if you've seen my last question about how to make a membership that can expire depending on what the player has bought. Racoonyz answered, "You would need to use a mix of os.time(), DataStores, and the MarketplaceService in order to do this." so I did. I made a script that uses a mix of os.time(), DataStores, and MarketPlaceService. I don't really know if my script works, I can't really test it out because I don't own my OWN developer products that I made. Why? Because I made the developer product in a group so I don't own the products even though I made it. Please check my script to see what's wrong!
local Subscriptions = {
VIP15Days = {
ID = 966297383,
Seconds = 1296000
},
VIP1Month = {
ID = 966297523,
Seconds = 2629746
},
VIPForever = {
ID = 966297617,
}
}
local DataStore = game:GetService("DataStoreService"):GetDataStore("Subscription")
local MarketPlaceService = game:GetService("MarketplaceService")
function VIPRewards(Player)
local Nametag = game.ReplicatedStorage.VIPNametag:Clone()
Nametag.Parent = Player.Character:WaitForChild("Head")
Nametag.Adornee = Player.Character:WaitForChild("Head")
Player:WaitForChild("PlayerGui").Reward.LocalScript.Disabled = false
end
game.Players.PlayerAdded:Connect(function(Player)
SubscriptionTimeLimit = Instance.new("NumberValue",Player)
SubscriptionTimeLimit.Name = "SubscriptionTimeLimit"
SubscriptionTimeLimit.Value = TimeSinceLastPurchase
local TimeNow = os.time()
local Data
pcall(function()
Data = DataStore:GetAsync(Player.UserId.."-Subscription")
TimeSinceLastPurchase = TimeNow - Data
end)
if MarketPlaceService:UserOwnsGamePassAsync(Player,Subscriptions.VIP15Days.ID) and Player:WaitForChild("SubscriptionTimeLimit").Value > 0 then
SubscriptionTimeLimit.Value = Subscriptions.VIP15Days.Seconds
VIPRewards(Player)
elseif MarketPlaceService:UserOwnsGamePassAsync(Player,Subscriptions.VIP1Month.ID) and Player:WaitForChild("SubscriptionTimeLimit").Value > 0 then
SubscriptionTimeLimit.Value = Subscriptions.VIP1Month.Seconds
VIPRewards(Player)
elseif MarketPlaceService:UserOwnsGamePassAsync(Player,Subscriptions.VIPForever.ID) then
-- It won't add value to the SubscritionTimeLimit, It would just give the player the rewards.
VIPRewards(Player)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId.."-Subscription",Player:WaitForChild("SubscriptionTimeLimit").Value)
end)
while wait(1) do
if SubscriptionTimeLimit.Value > 0 then
SubscriptionTimeLimit.Value = SubscriptionTimeLimit.Value - 1
end
end

2 comments
No, Don't tell me what to do
What do you mean? I'm just requesting to check if my script if it won't work