Hello, I am currently struggling with a script I made.
The script is supposed to open a GUI which displays a text button and when the text button is clicked the player can purchase a gamepass.
The GUI opens without any problem but the text button does not allow the player to purchase the gamepass.
I don’t know what to do, please help me !
here the script :
local MarketplaceService = game:GetService("MarketplaceService")
local MainFrame = script.Parent.MainGui
local GravityCoilGamepass = MainFrame.MainGui.GravityCoilFrame.Price
local ShopPart = workspace.ShopOpen
local player = game.Players.LocalPlayer
local GamepassID = 10567235
GravityCoilGamepass.MouseButton1Down:Connect(function()
local success, message = pcall(function()
HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID)
end)
if HasPass then
print("Player have the pass")
else
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end
ShopPart.ClickDetector.MouseClick:Connect(function()
if not script.Parent.Frame.Visible then
script.Parent.Frame.Visible = true
end
end)
I’ve forgot to say that this script is in the starter GUI and I have an other script placed in ServerScriptServive.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GamepassID = 10567235
game.Players.PlayerAdded:Connect(function(player)
local success, message = pcall(function()
HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID)
end)
if HasPass then
print("Player have own the pass")
local Gravity = game.ReplicatedStorage.GravityCoil:Clone()
Gravity.Parent = player.Backpack
end)
local function onPromptGamePassPurchaseFinished(player, purchasePassID, purchaseSuccess)
if purchaseSuccess == true and purchasePassID == GamepassID then
print(player.Name .. "Have purchase the pass")
local Gravity = game.ReplicatedStorage.GravityCoil:Clone()
Gravity.Parent = player.Backpack
end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
You need to debug your code and check your console before posting threads to this category. You do not close the MouseButton1Down connection for the gravity coil game pass button. Adding another end as well as a closing parenthesis is required.
It’s also a good idea to manage your tabbing properly so you can actually catch these issues. Studio’s tabbing can be broken sometimes so if you’re working with a different text editor then they catch these issues for you.
GravityCoilGamepass.MouseButton1Down:Connect(function()
local success, message = pcall(function()
HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID)
end)
if HasPass then
print("Player have the pass")
else
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end
end) -- < This needs to be here.
Also, for the server script, you have the exact same problem present, except this time you don’t close the if statement. Again, tabbing properly would help you here. Even I didn’t catch this until I read your code a second time over.
game.Players.PlayerAdded:Connect(function(player)
local success, message = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID)
end)
if success and message then
local Gravity = game.ReplicatedStorage.GravityCoil:Clone()
Gravity.Parent = player.Backpack
end
end)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GamepassID = 10567235
local HasPass = false
game.Players.PlayerAdded:Connect(function(player)
local success, message = pcall(function()
HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID)
end)
if HasPass then
print("Player have own the pass")
local Gravity = game.ReplicatedStorage.GravityCoil:Clone()
Gravity.Parent = player.Backpack
end
local function onPromptGamePassPurchaseFinished(player, purchasePassID, purchaseSuccess)
if purchaseSuccess == true and purchasePassID == GamepassID then
print(player.Name .. "Have purchase the pass")
local Gravity = game.ReplicatedStorage.GravityCoil:Clone()
Gravity.Parent = player.Backpack
end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
You forgot to have an end at the if HasPass and you need a HasPass varable.
this error had already happened to me but to solve it I had to remove the “end)” at the end and which made that the script did not work.
but even after putting it back, the script still doesn’t work. Is there an error that I haven’t fixed yet ?
GravityCoilGamepass.MouseButton1Down:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID) then
print(“Player have the pass”)
else
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end
end)
I tried to change some part of the script but it still don’t work.
I’m pretty sure that something in this script is wrong but I don’t know what…
This is the script from the StarterGui.
local MarketplaceService = game:GetService("MarketplaceService")
local MainGui = script.Parent.MainGui
local GravityCoilGamepass = MainGui.GravityCoilFrame.Price
local ShopPart = workspace.Jeff
local player = game.Players.LocalPlayer
local GamepassID = 10567235
local HasPass = false
GravityCoilGamepass.MouseButton1Down:Connect(function()
if MarketplaceService:UserOwnsGamePassAsync(player.UserID, GamepassID) then
print("Player have the pass")
HasPass = true
else
MarketplaceService:PromptGamePassPurchase(player, GamepassID)
end
end)
ShopPart.ClickDetector.MouseClick:Connect(function()
if not script.Parent.MainGui.Visible then
script.Parent.MainGui.Visible = true
end
end)