Help to gamepass auto train

hello developers as well as scriptwriters, I have one problem when a local player buys a gamepass from me, he starts an auto train how to make sure that the local player does not press the button forever himself, and after the purchase the auto train itself began

my script
local ID = 236988554 – Replace This with your gamepass ID
script.Parent.MouseButton1Click:Connect(function()
game:GetService(“MarketplaceService”):PromptGamePassPurchase(game.Players.LocalPlayer,
ID)
end)

      local cps = 30 -- clicks per second
      local active = false

      script.Parent.MouseButton1Click:connect(function()
  active = not active
      end)

      local player = game:GetService("Players").LocalPlayer

     while true do
 if player and active and player.Character then

	local tool = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool")

	if tool then
		tool:Activate()
	end

       end

      wait(1/cps)
          end

I want to make this gamepass like from the super power Fighting simulator game

1 Like

Could you edit your post rather than adding replies? It would make it a lot easier.

what do you mean? what to edit

Your post. Don’t add replies to your post if you are adding onto it.

I understand you, but will you help me with the script?

1 Like

It’s pretty hard to understand. Are you trying to get the player to auto train after they purchase the gamepass?

yes, that’s right, when a player buys from him, auto-pumping is triggered

You can try using a combination of the PromptGamePassPurchaseFinished event along with a coroutine to control the training. Kind of like this,

	if purchaseState == Enum.ProductPurchaseDecision.PurchaseGranted then
		active = true
		coroutine.wrap(activateTool)()
	end
end)

where to write this script on what line?

bro, I insert this script I get an error

"if purchaseState == Enum.ProductPurchaseDecision.PurchaseGranted then
	active = true
	coroutine.wrap(activateTool)()
end
end)"

It won’t work off the bat, it’s more of an idea on what you can fix.

help me fix it, I need to fix it very much