Change player's team upon developer product purchase

I’m trying to make it so when this developer product is purchased, the player’s team changes and it respawns them, though so far I’ve been unsuccessful. I’ve managed to get this all written down, but once purchased nothing happens and no errors are left behind either. Any clues as to why?

3 Likes
local MarketplaceService = game:GetService("MarketplaceService")
local ProductID = 000

MarketplaceService.PromptPurchaseFinished:Connect(function(Player, ID, Purchased)
if Player and ID == ProductID and Purchased then
local Humanoid = Player.Character:WaitForChild("Humanoid")
Player.TeamColor = BrickColor.new("Bright yellow")
Humanoid.Health = 0
end
end)

• Try using PromptPurchaseFinished Event, Anyways. Here’s the solution, you can also replace PromptPurchaseFinished with PromptGamePassPurchaseFinished If you certainly prefer that!

MarketplaceService.PromptPurchaseFinished:Connect(function(Player, ID, Purchased)

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, ID, Purchased)

• Are equivalent, but with a different event name.

1 Like

I’m getting the following error in the developer console with your script

ServerScriptService.TPScript:4: attempt to index function with ‘connect’

2 Likes

That’s strange, Hold on :smile: Let me get on it real quick.

1 Like
local MarketplaceService = game:GetService("MarketplaceService")
local ProductID = 000

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, ID, Purchased)
if Purchased and ID == ProductID then
local Humanoid = Player.Character:WaitForChild("Humanoid")
Player.TeamColor = BrickColor.new("Bright yellow")
Humanoid.Health = 0
end
end)

I did a little bit of edit, Wanna test it out?

2 Likes

Still isn’t working for some reason, though I’m not entirely sure if it’s the script this time. I’ve been getting an error saying “HttpError: ConnectFail.” im kinda new to scripting though so not 100% sure if that means much.

1 Like

Will you show me the error, So that I can check your problem.

1 Like

1 Like

That’s not actually the error coming from MarketplaceService, Or is it?

1 Like

Try running this in a Command Bar after playing in client.

local ProductID = 000
game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, ProductID)

2 Likes

OOPS! My bad, I mispelled “Prompt”. I editted the code you were suppose to copy and run it in a command bar.

Make sure you’re fulfilling this inside studio.

2 Likes

Still nothing happening

Hmmm, Try replacing LocalPlayer to your username. This is a purchase test. Make sure that the PromptGamePassPurchasedFinished Event is still there.

1 Like

still nothin going on for some reason

1 Like

No gui pops up? This is getting interesting.

1 Like

the gui pops up and I’m able to confirm the purchase and all that, it’s just the team changing part that doesnt seem to work

Try changing the event to

MarketplaceService.PromptPurchaseFinished:Connect(function(Player, ID, Purchased)

1 Like