Basically I've asked a question about how to make a membership that can expire. Racoonyz answered, "You would need to use a mix of os.time(), DataStores, and the MarketplaceService in order to do this." So I did it. I've made a script that uses a mix of os.time(), DataStores, and MarketplaceService.I didn't know if my script works because I made three developer products in a group and the script assures if the player has one of those developer products then it where the script rewards the player until a certain amount of time has passed since the player has bought one of those developer products. But since those three developer products are made in a group place instead of my place I don't own it so I can't really know if my script worked? Please correct my script!
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 = 0
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 wont add the value of 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
