So basically I'm trying to make a subscription with a time limit that runs out and when the time limit runs out the player is no longer subscribed. I've made a script but I can't get it to work! Please help! Here's the 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
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() do
if SubscriptionTimeLimit.Value == 0 then
repeat
SubscriptionTimeLimit.Value = SubscriptionTimeLimit.Value - 1
until SubscriptionTimeLimit.Value == 0
end
end

2 comments
you use a function called tick() to get the real time in ms then you check if the new tick() is higher or equal to the tick you set
oml that was literally what I did :3 but I used os.time() instead bc I wnna make sure it returns the unix time of the epoch thing