Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MPS = game:GetService("MarketplaceService")
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local player = Players.LocalPlayer
- local skipStageButton = script.Parent -- This script should be a child of the ImageButton
- local DEVELOPER_PRODUCT_ID = 3359006786 -- Replace with your actual Developer Product ID
- local skipStageEvent = ReplicatedStorage:WaitForChild("SkipStageRequest")
- local MAX_FREE_SKIPS = 5
- local freeSkipsLeft = 0
- -- Group ID for free skip countdown feature
- local GROUP_ID = 289054289
- -- Countdown settings
- local COUNTDOWN_TIME = 300 -- 5 minutes (300 seconds)
- local countdown = COUNTDOWN_TIME
- -- Reference to the SkipsLeft TextLabel in PlayerGui
- local skipsLeftLabel = nil
- local countdownLabel = nil
- local function findSkipsLeftLabel()
- local playerGui = player:FindFirstChild("PlayerGui")
- if playerGui then
- local displaySkips = playerGui:FindFirstChild("DisplaySkips")
- if displaySkips then
- return displaySkips:FindFirstChild("SkipsLeft")
- end
- end
- return nil
- end
- local function findCountdownLabel()
- local playerGui = player:FindFirstChild("PlayerGui")
- if playerGui then
- local displaySkips = playerGui:FindFirstChild("DisplaySkips")
- if displaySkips then
- return displaySkips:FindFirstChild("Countdown")
- end
- end
- return nil
- end
- -- Function to update the SkipsLeft label
- local function updateSkipsLeftLabel()
- if not skipsLeftLabel then
- skipsLeftLabel = findSkipsLeftLabel()
- end
- if skipsLeftLabel then
- skipsLeftLabel.Text = "Free Skips Left: " .. tostring(freeSkipsLeft) .. " / " .. tostring(MAX_FREE_SKIPS)
- skipsLeftLabel.Visible = true
- end
- end
- local function formatTime(seconds)
- local minutes = math.floor(seconds / 60)
- local secs = seconds % 60
- return string.format("%02d:%02d", minutes, secs)
- end
- local function updateCountdownLabel()
- if not countdownLabel then
- countdownLabel = findCountdownLabel()
- end
- if countdownLabel then
- if freeSkipsLeft >= MAX_FREE_SKIPS then
- countdownLabel.Text = "Max free skip reached"
- countdownLabel.Visible = true
- else
- countdownLabel.Text = "Next Free Skip In: " .. formatTime(countdown)
- countdownLabel.Visible = true
- end
- end
- end
- -- For non-group members, update UI to show group-only feature
- local function setGroupOnlyUI()
- if not skipsLeftLabel then
- skipsLeftLabel = findSkipsLeftLabel()
- end
- if not countdownLabel then
- countdownLabel = findCountdownLabel()
- end
- if skipsLeftLabel then
- skipsLeftLabel.Text = "Join our group for free skips!"
- skipsLeftLabel.Visible = true
- end
- if countdownLabel then
- countdownLabel.Text = "Free skips are a group feature"
- countdownLabel.Visible = false
- end
- end
- local function onPromptProductPurchaseFinished(plr, productId, wasPurchased)
- if plr == player and productId == DEVELOPER_PRODUCT_ID and wasPurchased then
- skipStageEvent:FireServer()
- end
- end
- -- Main logic
- if player:IsInGroup(GROUP_ID) then
- -- Initial update
- updateSkipsLeftLabel()
- updateCountdownLabel()
- skipStageButton.MouseButton1Click:Connect(function()
- if freeSkipsLeft > 0 then
- freeSkipsLeft = freeSkipsLeft - 1
- updateSkipsLeftLabel()
- skipStageEvent:FireServer()
- -- If we just dropped below max, restart timer and show countdown again
- if freeSkipsLeft == MAX_FREE_SKIPS - 1 then
- countdown = COUNTDOWN_TIME
- updateCountdownLabel()
- end
- else
- MPS:PromptProductPurchase(player, DEVELOPER_PRODUCT_ID)
- end
- end)
- MPS.PromptProductPurchaseFinished:Connect(onPromptProductPurchaseFinished)
- -- Timer loop
- task.spawn(function()
- while true do
- if freeSkipsLeft < MAX_FREE_SKIPS then
- if countdown > 0 then
- countdown = countdown - 1
- else
- freeSkipsLeft = freeSkipsLeft + 1
- updateSkipsLeftLabel()
- countdown = COUNTDOWN_TIME
- end
- updateCountdownLabel()
- else
- -- If max skips, show max message and pause timer
- countdown = 0
- updateCountdownLabel()
- -- Wait until a skip is used before resuming timer
- repeat
- task.wait(0.5)
- until freeSkipsLeft < MAX_FREE_SKIPS
- countdown = COUNTDOWN_TIME
- updateCountdownLabel()
- end
- task.wait(1)
- end
- end)
- -- Listen for PlayerGui changes in case the GUI reloads (e.g., after reset)
- player.CharacterAdded:Connect(function()
- skipsLeftLabel = nil
- countdownLabel = nil
- task.wait(1)
- updateSkipsLeftLabel()
- updateCountdownLabel()
- end)
- else
- -- Not in group: disable free skip logic, update UI
- setGroupOnlyUI()
- skipStageButton.MouseButton1Click:Connect(function()
- MPS:PromptProductPurchase(player, DEVELOPER_PRODUCT_ID)
- end)
- -- Listen for PlayerGui changes in case the GUI reloads (e.g., after reset)
- player.CharacterAdded:Connect(function()
- skipsLeftLabel = nil
- countdownLabel = nil
- task.wait(1)
- setGroupOnlyUI()
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment