When I Buy Item The Other Items That i Made Also Work Even I Didn't Buy it?

You can write your topic however you want, but you need to answer these questions:
1. What do you want to achieve? Keep it simple and clear!
I Want To Have Item That When Player Buy It
Add The Prize To Donated Value That in The leaderstats , Only For The Item That I Have Bought it
And The Effect Should Work Only In The Item That I Have Bought it

2. What is the issue? Include screenshots / videos if possible!
when I Buy One Item It Fires The Other Item Too And Also Put The Prize Value OF other To the Donated And The Effects Should Work In The Item That I bought Not In The Other, I hope This Screenshot Help you
BugProblem

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
No , I Didn’t Find
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local GamepassId = script.Parent.Parent.Parent.GamepassID
local MarketService = game:GetService("MarketplaceService")
local Prox = script.Parent
local Effect = script.Parent.Parent.Effect:GetChildren()
local SoundEffect = script.Parent.Parent.Donate
Prox.Triggered:Connect(function(Player)
	MarketService:PromptGamePassPurchase(Player,GamepassId.Value)
end)

local Id = GamepassId.Value
MarketService.PromptGamePassPurchaseFinished:Connect(function(Player,Id,Bool)
	if Bool == true then
		local Asset = game:GetService("MarketplaceService"):GetProductInfo(Id,Enum.InfoType.GamePass)
		Player.leaderstats.Donated.Value = Player.leaderstats.Donated.Value + Asset.PriceInRobux
		local PlayerName = Asset.Creator.Name
		for i,v in pairs(game.Players:GetChildren()) do
			if v.Name == PlayerName then
				v.leaderstats.Rised.Value = v.leaderstats.Rised.Value + Asset.PriceInRobux
			end
		end
		for i,v in pairs(Effect) do
			v.Enabled = true
		end
		SoundEffect:Play()
		wait(6)
		for i,v in pairs(Effect) do
			v.Enabled = false
		end
	end
end)


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Maybe try disabling the proximity prompt for a short while after it is triggered, i.e.

Prox.Triggered:Connect(function(Player)
	Prox.Enabled = false
	MarketService:PromptGamePassPurchase(Player,GamepassId.Value)
end)

And then enable it again after this function finishes:

MarketService.PromptGamePassPurchaseFinished:Connect(function(Player,Id,Bool)
	-- ...
	Prox.Enabled = true;
end)
1 Like

Thx For Trying To Help , But It Didn’t Work

idk where Is the mistake in my script

Try commenting out this line:

local Id = GamepassId.Value;

Because it is not used and it is named the same as the input to this function: MarketService.PromptGamePassPurchaseFinished:Connect(function(Player,**Id**,Bool) and keep disabling the prompt that you already tried, it may be spamming the prompt and changing the value within the function. See if that works.

1 Like

I Deleted The "local Id = GamepassId.Value; t
but Its Still Showing The Same issue

And you are still disabling the prompt on the Triggered event?

And what value is in GamepassId.Value because this is never changed in the code I can see.

yes i disabled it
and open it after it Function Finshes
, The Value in the gamepass is the id
The Deleted Code Was Useless Thx for that
New Script

GamepassId.Value

Never changes so the Prox.Triggered event is buying whatever is in this which never changes, is this initalised as empty (nil) when Prox.Triggered is fired? i.e. put a print in here:

Prox.Triggered:Connect(function(Player)
	print(GamepassId.Value)
	Prox.Enabled = false
	MarketService:PromptGamePassPurchase(Player,GamepassId.Value)
end)

Can I Help You With Video Or Model of the problem
ok i will try the print

It isnt nil , it have the Id of the game pass
Thx for trying to help me :frowning_face:
im sorry if i take some of your time
it Print
“35510252”

Its no problem, I like to help if I can. Are you using the same proximity prompt for all items, or does this code exist in another script parented to the other proximity prompts for each of the items they can buy?

1 Like

OH sorry i Forgot to Put This Screenshot

Okay this helps, let me think for a moment, I don’t think the logic is failing in your code, it’s something else that is causing this.

i will Put It in a new place and call you back

Yeah the message for purchase is being received in all Scripts. You need to put the logic to handle purchase in a single script. That is why all of them are being bought, because MarketPlace is sending the message and every script is receiving the response. You need to use something like this and remove the other Scripts from each prompt.

local PromptService = game:GetService("ProximityPromptService")

local function OnPromptTriggered(Prompt, Player)
	local Id = Prompt.["Path to ID"].GamepassID;
	if not Id then return end
	MarketService:PromptGamePassPurchase(Player,Id);
end

-- rest of code
1 Like

Sorry i was AFK i will try it now

1 Like

I Think This Is The Solution But How My Script Should Look Like ,

You need a single Script parented to the same parent as the Models named “CarToy”,“HotDog” and “Lemon”. Remove all the other Scripts from inside the “BuyProx” children. Then move all of the GamepassId's into the proximity prompts, or just lose the GamepassId values and simply name the “BuyProx” prompts to the Id of the item. Then you can just do this:

local PromptService = game:GetService("ProximityPromptService")

local function OnPromptTriggered(Prompt, Player)
	MarketService:PromptGamePassPurchase(Player,Prompt.Name);
end

-- rest of your code here i.e.
MarketService.PromptGamePassPurchaseFinished:Connect(function(Player,Id,Bool)
	-- ...
end)
1 Like

Thx so Much Man for this Thing , i Will Try it I think you did it and reached to the solution
Thx So much i will credit you in my game :kissing_heart:

1 Like