How do I turn this into a gamepass?

I was browsing through my old games and came across this Jump-Roll script which is triggered when a player presses C.
The script working allright, how do I make it such that this can only be done if the player owns a gamepass?
It is confusing me a little and would love some help in this.
The script is as follows :-

local MaxJ = 1;
local MaxD = 1;
local JumpDifference = 0.1;

local root = script.Parent:WaitForChild("HumanoidRootPart");
local head = script.Parent:WaitForChild("Head");
local humanoid = script.Parent:WaitForChild("Humanoid");
local particle = script:WaitForChild("Particle");
particle.Parent = nil;

local anim;
if (humanoid.RigType == Enum.HumanoidRigType.R15) then
	anim = humanoid:LoadAnimation(script:WaitForChild("Roll_R15"));
else
	anim = humanoid:LoadAnimation(script:WaitForChild("Roll_R6"));
end

local canJump = true;
local jumpCount = 0;

local canDive = true;
local diveCount = 0;
local totalDives = 0;

local function createParticle(cf, t)
	game.ReplicatedStorage.Effects.Attack:Play()
	local part = Instance.new("Part");
	part.Size = Vector3.new(4, 4, 4)
	part.Anchored = true;
	part.CanCollide = false;
	part.Transparency = 1;
	part.CFrame = cf;
	part.Parent = game.Workspace;
	
	local clone = particle:Clone();
	clone.Enabled = true;
	clone.Parent = part;
	
	local life = clone.Lifetime;
	for i = 0, 1.1, 0.1 do
		clone.Lifetime = NumberRange.new((1-i)*life.Min, (1-i)*life.Max + 0.1);
		wait(t*0.1);
	end

	game:GetService("Debris"):AddItem(part, t);
end

local function onStateChange(old, new)
	if (new == Enum.HumanoidStateType.Landed or new == Enum.HumanoidStateType.Swimming or new == Enum.HumanoidStateType.Running or new == Enum.HumanoidStateType.RunningNoPhysics) then	
		canDive = true;
		canJump = true;
		jumpCount = 0;
		diveCount = 0;
		anim:Stop();
	elseif (new == Enum.HumanoidStateType.Freefall or new == Enum.HumanoidStateType.Flying) then
		wait(JumpDifference)
		canJump = true;
		canDive = true;
	end
end

local function onJumpRequest()
	if (not humanoid or humanoid:GetState() == Enum.HumanoidStateType.Dead) then
		return;
	end
	
	if (canJump and jumpCount < MaxJ) then
		canJump = false;
		jumpCount = jumpCount + 1;
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping);
		
		if (jumpCount > 1) then
			if (jumpCount % 2 == 0 or humanoid:GetState() == Enum.HumanoidStateType.Flying) then
				anim:Play(nil, nil, 2.5);
			end
			local z = root.CFrame:vectorToObjectSpace(root.Velocity).z;
			createParticle(root.CFrame * CFrame.new(0, -1, 0), .3);
		end
	end
end

local function onInput(input, process)
	if (process or not humanoid or humanoid:GetState() == Enum.HumanoidStateType.Dead) then
		return;
	end	
	
	if (input.KeyCode == Enum.KeyCode.C and humanoid:GetState() == Enum.HumanoidStateType.Freefall and canDive and diveCount < MaxD) then
		canDive = false;
		diveCount = diveCount + 1;
		totalDives = totalDives + 1;
		
		anim:Stop();
		humanoid:ChangeState(Enum.HumanoidStateType.Flying);
		root.Velocity = root.CFrame:vectorToWorldSpace(Vector3.new(0, humanoid.JumpPower, -humanoid.WalkSpeed*3));
		root.RotVelocity = root.CFrame:vectorToWorldSpace(Vector3.new(-math.rad(135), 0, 0));
		createParticle(root.CFrame * CFrame.new(0, -1, -3), .3);
		

		local currentDive = totalDives;
		wait(0.5);
		if (currentDive == totalDives) then
			root.RotVelocity = root.CFrame:vectorToWorldSpace(Vector3.new(0, 0, 0));
		end
	end
end

local function onTouched(touchingPart, humanoidPart)
	if (humanoid:GetState() == Enum.HumanoidStateType.Flying and touchingPart.CanCollide) then
		local ray = Ray.new(humanoidPart.Position, -humanoidPart.Velocity * 10);
		local hit, pos, normal, material = game.Workspace:FindPartOnRayWithWhitelist(ray, {touchingPart});
	
		if (material ~= Enum.Material.Water and material ~= Enum.Material.Air and normal:Dot(Vector3.new(0, 1, 0)) <= 0.5) then
			root.Velocity = (normal + Vector3.new(0, 1, 0)) * 30;
			anim:Play(nil, nil, 2.5);
		end
		
		humanoid:ChangeState(Enum.HumanoidStateType.Freefall);
	end
end

if (MaxD > 0) then
	humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false);
	humanoid.Touched:Connect(onTouched);
	game:GetService("UserInputService").InputBegan:Connect(onInput);
end

humanoid.StateChanged:Connect(onStateChange);
game:GetService("UserInputService").JumpRequest:Connect(onJumpRequest);

Just in case you want the location as well :-
image

try to use MarketplaceServer:UserOwnsGamePassAsync(UserId, GamePassId)?

do like this:

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(1234567890, 12345678) == true then
   -- code here
end

DevHub:

I tried it a while back but didnt get the expecting result, still browsing for a way which could work

are you trying to check it after player purchases the gamepass?

Create a gamepass, detect if the player has it with MarkerPlaceService and if it does, give the local script into their backpack and GearFolder

In a Server Script

local MPS = game:GetService('MakerPlaceService');
local GamePassID = --your gamepass id--

for i, player in pairs(game.Players:GetChildren())
   if(MPS:UserOwnsGamePassAsync(GamePassID, player.UserId)) then
       local Dash = game.ReplcatedStorage.Dash:Clone()
       Dash.Parent = player.Backpack
-- You can add the Gear Folder of the player
   end
end

You can also refer to this :

if yes, then use MarketplaceService:PromptGamePassPurchaseFinished(player, GamePassId, WasPurchased)

(not making the code because I’m about to sleep, and there’s a sample code there too)

DevHub:

Here you prompt a purchase and not giving out the Gamepass and not checking

what are you even trying to say?

This function prompts the end of a purchase. Looping through player and giving them with UserOwnsGamePassAsync() is more efficient

Not saying it wont work but for practice its better