Infinite skips gamepass

im doing infinite skips gamepass there is way to improve this script? and how do i add cooldown to this script. Thanks

Checkpoints(serverscriptservice):

local Checkpoints = workspace:WaitForChild("Checkpoints")
local Skip = ReplicatedStorage:WaitForChild("Skip")
local players = game.Players:GetPlayers()
local finish = 0

Skip.OnServerInvoke = function(player)
	local players = game.Players:GetPlayers()
	local finish = 0
	for i=1, #players do
		if finish == 0 then
			finish = 1 
			players[i].leaderstats.Stage.Value = players[i].leaderstats.Stage.Value + 1
			players[i].Character:MoveTo(Checkpoints:FindFirstChild(players[i].leaderstats.Stage.Value).Position)
		end
	end
end

local script:

local TextButton = script.Parent

local Checkpoints = workspace:WaitForChild("Checkpoints")

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local StageLeaderstat = player:WaitForChild("leaderstats"):WaitForChild("Stage")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Skip = ReplicatedStorage:WaitForChild("Skip")

TextButton.MouseButton1Click:Connect(function()

local Response = Skip:InvokeServer()

end)
1 Like

Add a variable that tracks the last time a player skipped.

local TextButton = script.Parent

local Checkpoints = workspace:WaitForChild("Checkpoints")

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local StageLeaderstat = player:WaitForChild("leaderstats"):WaitForChild("Stage")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Skip = ReplicatedStorage:WaitForChild("Skip")

local lastSkipTick = tick();
local cooldownTime = 3; --Change this if you'd like

TextButton.MouseButton1Click:Connect(function()
    if tick() - lastSkipTick >= cooldownTime then
        lastSkipTick = tick();
        local Response = Skip:InvokeServer()
    end
end)
1 Like

i solve the cooldown problem already, thank you