Why does this Gam ePass thing Not Working?

Hi, i made something like a part and inside of it, a surface GUI and inside a Image button and then inside of it a local script.

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

local gamePassId = 22612992


script.Parent.MouseClick:Connect(function()
	marketPlaceService:PromptGamePassPurchase(player,gamePassId) 
end) 

but that script not even running :frowning:

image

Does anyone know why this is happening?

:slight_smile: Waiting for your Help Buddies…

You should be using the MouseButton1Click event. MouseClick isn’t a valid event of TextButton instances.

still not working :frowning: !

tbh im not sure but the first parameter for PromptGamePassPurchase would be the player id not the player instance and the ui buttons use MouseButton1Click as their event not MouseClick

local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local marketPlaceService = game:GetService("MarketplaceService")
local gamePassId = 22612992

script.Parent.MouseButton1Click:Connect(function()
	marketPlaceService:PromptGamePassPurchase(player.UserId, gamePassId) 
end)

still there are problems :frowning: !

still, there are problems :(! i tested all u r solutions before i posted here

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

local gamePassId = 22612992


workspace.Part.SurfaceGui.ImageButton.MouseButton1Click:Connect(function()
	marketPlaceService:PromptGamePassPurchase(player.UserId,gamePassId) 
end)

try this,i just realised that youre putting it in a part which is in the workspace and local scripts dont work on workspace,instead you have to put the script in the PlayerGui and reference the ui from the PlayerGui

Sorry to tell again, that’s still not working ;( ;(

you sure? could you show a video of it not working?

yes i m pretty 100% sure a i m testing it again and again

The reason why it’s not working here is because the workspace has no capital W, change it from ‘workspace’ to ‘Workspace’ (i think)

um not exactly true you can use workspace which is a shorter form of game.Workspace

if its not the players character then a locAL script will not run

no thats not the problem actually.
The script is Not running !

workspace is supposed to be lowercase.

oh yeah, my bad i forgot about that, i’m still new to coding

local players = game:GetService("Players")
local player = players.LocalPlayer
local marketPlaceService = game:GetService("MarketplaceService")
local gamePassId = 22612992

game.Workspace.GamePassPart.SurfaceGui.ImageButton.MouseButton1Click:Connect(function()
	marketPlaceService:PromptGamePassPurchase(player.UserId, gamePassId) 
end)

Put the script into the StarterPlayerScripts folder, rename the part to “GamePassPart” make sure it is parented to the workspace.

this wont work lol as you used game.workspace instead of game.Workspace

on there, the “w” should be capitalized