Script shows no errors but does not work

What i’m trying to do is to make it where if a player has a gamepass and then they click T then it prints out something for now.

local MarketPlaceService = game:GetService("MarketplaceService")
local YourGamepassID = 13771426
local player = game.Players.LocalPlayer


something = false
if workspace:FindFirstChild("Enemy") ~= nil then
	Print("Ready to fire")
something = true
end

if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, tonumber(YourGamepassID))
then
	





function onKeyPress(inputObject, gameProcessedEvent)
		if (inputObject.KeyCode == Enum.KeyCode.T and something)
		then
		print("It worked")
		
		end

	end
	


game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Any help would be nice thanks!

A few things.

local MarketPlaceService = game:GetService("MarketplaceService")
local YourGamepassID = 13771426
local player = game.Players.LocalPlayer
local HasGamepass = false
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, tonumber(YourGamepassID)) then
      HasGamepass = true
end


function onKeyPress(inputObject, gameProcessedEvent)
        if (inputObject.KeyCode == Enum.KeyCode.T) then
              if HasGamepass == true then
		        print("It worked")
              end
        end
end


game:GetService("UserInputService").InputBegan:connect(onKeyPress)

You try to load a function if they had a gamepass. Also you made the function scoped so that its only within that if statement.

This above code should fix those issues.

still does not work I have it in starter gui is that right?