Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(Answered OwO)How to make a Subscription that has time limit like RoBeats VIP?

Asked by 4 years ago
Edited 4 years ago

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
1
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 Gameplayer365247v2 1055 — 4y
0
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 DizzyGuy70 38 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

this is not an answer but i write it here to read it easier for example on my comment on vip15days you could you VIP15Days = { ID = 966297383, Seconds = tick() + 1296000 }, then when you check you do like this local checktick = tick() if checktick >= Seconds then

0
Thank you so much! With you're advice I finally got a solution to find out the certain number seconds after the player has bought the developer product! DizzyGuy70 38 — 4y
0
np Gameplayer365247v2 1055 — 4y
Ad

Answer this question