Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStoreService = game:GetService("DataStoreService")
- local HttpService = game:GetService("HttpService")
- local TeleportService = game:GetService("TeleportService")
- local MarketplaceService = game:GetService("MarketplaceService")
- local Players = game:GetService("Players")
- local vipStore = DataStoreService:GetDataStore("VipServerData")
- local serverCodeFormat = "%s-%s"
- local config = require(script.Config)
- local vip = {}
- local function HandlePurchase(receiptInfo)
- local plr = Players:GetPlayerByUserId(receiptInfo.PlayerId)
- if not plr then
- return Enum.ProductPurchaseDecision.NotProcessedYet
- end
- if plr then
- local success = vip.CreateServer(plr)
- if success then
- return Enum.ProductPurchaseDecision.PurchaseGranted
- else
- return Enum.ProductPurchaseDecision.NotProcessedYet
- end
- end
- end
- MarketplaceService.ProcessReceipt = HandlePurchase
- function vip.PromptPurchase(plr)
- MarketplaceService:PromptProductPurchase(plr,config.ProductId)
- end
- function vip.CreateServer(plr)
- local vipData
- local success,res = pcall(function()
- vipData = vipStore:GetAsync(plr.UserId)
- if vipData then
- warn("Player already has a VIP server!")
- return nil
- else
- vipData = {
- Owner = plr.UserId,
- TeleportCode = TeleportService:ReserveServer(game.PlaceId),
- ServerCode = serverCodeFormat:format(plr.UserId,HttpService:GenerateGUID(false):sub(1,5)),
- ExpiryDate = os.time() + (config.Validity * 86400)
- }
- end
- vipStore:SetAsync(plr.UserId,vipData)
- end)
- if success then
- return vipData
- else
- warn(res)
- return nil
- end
- end
- function vip.GetServerInfo(plr)
- local serverData
- local success,res = pcall(function()
- serverData = vipStore:GetAsync(plr.UserId)
- if not serverData then return warn("Server doesn't exist!") end
- end)
- if not success then
- warn(res)
- else
- return serverData
- end
- end
- function vip.TeleportToServer(plr,serverCode)
- local serverData
- local userId = serverCode:split("-")[1]
- local success,res = pcall(function()
- serverData = vipStore:GetAsync(tonumber(userId))
- if not serverData then return warn("Server doesn't exist!") end
- if os.time() - serverData.ExpiryDate >= 0 then
- serverData = nil
- vipStore:RemoveAsync(tonumber(userId))
- return warn("VIP server expired!")
- end
- if serverData and serverData.ServerCode == serverCode then
- TeleportService:TeleportToPrivateServer(game.PlaceId,serverData.TeleportCode,{plr})
- end
- end)
- if not success then
- warn(res)
- end
- end
- return vip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement