My gamepass script that creates a part isn't working

My developer product is not working, please help out!

Please note: I am editing a free model, I have hacked away a lot of crap that I didn’t need and these are the only two scripts.

The thing that creates the part:
local Id = 1226966447

game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) then 
		Instance.new("Part")	
	en
end)

Code that prompts the purchase

local gamepassId = 1226966447
script.Parent.ClickDetector.MouseClick:connect(function(player)
	game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamepassId)
end)

You missed a “d”.

Also make the part into a variable to edit more properties than just the parent:

game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) then 
		local Part = Instance.new("Part")
        Part.Parent = game.Workspace
	end
end)
1 Like

The part isn’t being parented to anything.
This script parents it to workspace

game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) then 
		local part = Instance.new("Part")
                part.Parent = game.Workspace
	end
end)
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamepassId = 1226966447

Players.PlayerAdded:connect(function(Player)
	if MPS:UserOwnsGamePassAsync(Player.UserId, gamepassId) then 
		local part = Instance.new("Part")
		part.Parent = workspace
	end
end)
local MPS = game:GetService("MarketplaceService")
local gamepassId = 1226966447
local part = script.Parent
local button = script.Parent:WaitForChild("ClickDetector")

button.MouseClick:connect(function(player)
	MPS:PromptGamePassPurchase(player, gamepassId)
end)

You were missing an end statement and the gamepassId declaration in the first script, I’ve also declared MarketplaceService outside of the callback connected to the event because it’s more efficient to do it this way. You also need to set the “Parent” property of the created part otherwise the part will be parented to nil and won’t appear.

Also if you want it to make the part as soon as they buy the gamepass, then add this script to ServerScriptService:

local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, pass_id, was_purchased)
    if was_purchased == true then
       local Part = Instance.new("Part")
       Part.Parent = game.Workspace
    end
end)

Also, organizing stuff inside the script is good too, and there are many examples and explanations on why it is good. Obviously that’s not your goal, but I don’t have time to make the script neat because I’m on mobile and I’m just trying to help, not compete.

Thanks to @jsnotlout1 @Forummer and @Ioveczour for helping me :slight_smile: !

@jsnotlout1 @Forummer @Ioveczour

It’s not working, scripts are the same. It gives me the “something went wrong” thing when I purchase it.

This is the layout, it also does not create the part.

Screenshot (611)

Looking at the gamepassId, I believe it is a developer product not a gamepass, so instead use.

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productId = 1226966447

Players.PlayerAdded:connect(function(Player)
	if MPS:PlayerOwnsAsset(Player, productId) then 
		local part = Instance.new("Part")
		part.Parent = workspace
	end
end)
local MPS = game:GetService("MarketplaceService")
local productId = 1226966447
local part = script.Parent
local button = script.Parent:WaitForChild("ClickDetector")

button.MouseClick:connect(function(player)
	MPS:PromptProductPurchase(player, productId)
end)
1 Like
local Id = 1226966447

game.Players.PlayerAdded:connect(function(Player)
	if game:GetService("MarketplaceService"):PromptProductPurchase(Player.UserId, Id) then 
		Instance.new("Part", game.Workspace)	
	end
end)
local gamepassId = 1226966447

script.Parent.ClickDetector.MouseClick:connect(function(player)
	game:GetService("MarketplaceService"):PromptProductPurchase(player.UserId, gamepassId)
end)
1 Like

Hmm. It works pretty well, but the part does not go in. Would you mind running it from your end?

Try my script. It should work.