Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Struggling with Syntax errors on a gamepass button, can i please have help?

I've been coding a gamepass button on my game, but i can't find a way to fix the syntax errors as i am a new coder. can somebody please help with the syntax errors?

local button = script.Parent

local function onButtonActivated(local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 22453139 

s
local function promptPurchase()

	local player = Players.LocalPlayer
	local hasPass = false

	local success, message = protocall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end

	if hasPass then message (You already own this pass)
		
	else
		
		MarketplaceService:PromptGamePassPurchase(player, gamePassID)
	end
end)
	print("Button activated!")
	

end

button.Activated:Connect(onButtonActivated)

1 comment

0

I have found a few fixes to my own code, such as ("You already own this pass") instead of the one missing the parenthasis

1 answer

✓ Accepted answer

I'm not sure if this would work but I tried

local button = script.Parent
	 
	local function onButtonActivated() local MarketplaceService = game:GetService("MarketplaceService")
		local Players = game:GetService("Players")
		 
		local gamePassID = 22453139
		 
		local function promptPurchase()
		 
			    local player = Players.LocalPlayer
			    local hasPass = false
		 
			    local success, message = protocal(function()
				        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
				    end)
			 
			    if not success then
				        warn("Error while checking if player has pass: " .. tostring(message))
				        return
					    end
			 
			    if hasPass then message ("You already own this pass")
				 
				    else
				 
				        MarketplaceService:PromptGamePassPurchase(player, gamePassID)
				    end
			end
		    print("Button activated!")
		 
		 
		end
	 
	button.Activated:Connect(onButtonActivated)

1 comment

0

thank you so much

This discussion is preserved as it was. New answers, comments, and votes are closed.