I Want One DevProduct For Multiple Items

Hello. I have a list of UI elements (TextButtons) that when clicked, will prompt you to purchase my DevProduct. More specifically, I want the player to get moved to a certain area on the map depending on the name of what the player clicked.

I see that DevProducts can only have the Player, ProductID, Equipable/Boolean thing and Currency Type, it would help if there was a way to also pass on a string.

Basically, I can’t seem to get the gamepass system to teleport the player, I’ve tried saving the name of the UI the player clicked onto a StringValue located in the player’s backpack and relaying that to the Gamepass script, but to no avail (returns nil)

Gamepass script:

	Products = { -- developer_product_id = function(profile)
		[1684948991] = function(profile, player)
			local Emoji = player.Backpack.Emoji.Value
			print(Emoji)
			print("Hi",profile,player.Backpack.Emoji.Value)
			local Position = workspace.Emojis:FindFirstChild(Emoji).Badge.Position
			player.Character:MoveTo(Position)
		end,
	},

Prompt Script:

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

for i,v in script.Parent:GetDescendants() do
	if v.Name == "Purchase" then
		v.Activated:Connect(function()
			player.Backpack.Emoji.Value = v.Parent.Name
			MarketplaceService:PromptProductPurchase(player,1684948991)
			print(player.Backpack.Emoji.Value)
		end)
	end
end

Any help or suggestions would be greatly appreciated. Also, I have a few hundred UI elements players can click, so I do NOT want to individually make DevProducts for each one. Thank you.

The server couldn’t see your .Emoji value change because you set the value on the client. Use RemoteEvents to communicate with the server.

  1. Add a new RemoteEvent in ReplicatedStorage called EmojiBought:
    image

  2. Change your LocalScript to this:

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local EmojiBought = ReplicatedStorage:WaitForChild("EmojiBought")

for i, v in script.Parent:GetDescendants() do
	if v.Name == "Purchase" then
		v.Activated:Connect(function()
			EmojiBought:FireServer(v.Parent.Name)
			player:GetAttributeChangedSignal("SelectedEmoji"):Wait()
			MarketplaceService:PromptProductPurchase(player,1684948991)
		end)
	end
end
  1. Change your gamepass script to this:
--//Not sure why you didn't send me the whole script but just move this function somewhere
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local EmojiBought = ReplicatedStorage.EmojiBought

EmojiBought.OnServerEvent:Connect(function(player, emoji)
	player:SetAttribute("SelectedEmoji", emoji)
end)

--//Gamepass code
Products = { -- developer_product_id = function(profile)
	[1684948991] = function(profile, player)
		local Emoji = player:GetAttribute("SelectedEmoji")
		local Position = workspace.Emojis:FindFirstChild(Emoji).Badge.Position
		player.Character:MoveTo(Position)
	end,
},

Make sure to get rid of your .Emoji StringValue as it’s not needed.

That works perfectly, thank you!

Regarding your question, I’m using ProfileService, it has a lot of extra code that I thought wasn’t relevant to what I was doing and would just be extra clutter.

Alright, that makes sense. Sorry if I came off rude now that I look at it lol. If you have any questions, feel free to ask.

1 Like

Actually, a better way to do this is to prompt the purchase on the server so we don’t need the wait. A more fitting name for the RemoteEvent would be EmojiPurchase now so I would change it to that so you can understand it better later.

LocalScript:

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local EmojiBought = ReplicatedStorage:WaitForChild("EmojiBought")

for i, v in script.Parent:GetDescendants() do
	if v.Name == "Purchase" then
		v.Activated:Connect(function()
			--//Fire event to purchase emoji
			EmojiBought:FireServer(v.Parent.Name)
		end)
	end
end

Server:

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local EmojiBought = ReplicatedStorage.EmojiBought

EmojiBought.OnServerEvent:Connect(function(player, emoji)
	player:SetAttribute("SelectedEmoji", emoji)
	MarketplaceService:PromptProductPurchase(player, 1684948991)
end)

--//Gamepass code
Products = { -- developer_product_id = function(profile)
	[1684948991] = function(profile, player)
		local Emoji = player:GetAttribute("SelectedEmoji")
		local Position = workspace.Emojis:FindFirstChild(Emoji).Badge.Position
		player.Character:MoveTo(Position)
	end,
},
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.