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
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.
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.
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:
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?
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
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)