I have a certain powerup that you can touch in game and be prompted to purchase it for 5 robux.
Unfortunately, it is prompting literally everyone in the game (at the same time). I realize this might be a simple fix but I can’t figure out how to fix it. (It is a LocalScript)
Here is the code responsible for the prompting:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
player = game.Players.LocalPlayer
Powerup.Touched:Connect(function(h)
if db == false and h.Parent:FindFirstChild("Humanoid") then
db = true
MarketplaceService:PromptProductPurchase(player,productId)
wait(1)
db = false
end
end)
It seems like the local scripts will all detect the touch, so it would be better to use a server script under the part that should be touched and prompt the player from there.
Example:
--Server Script under the part that prompts purchase
local Players = game:GetService("Players")
local mps = game:GetService("MarketPlaceService")
local debounce = false
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit and hit.Parent:FindFirstChild("Humanoid") then
local plr = Players:GetPlayerFromCharacter(hit.Parent)
mps:PromptProductPurchase(plr.UserId, product id)
debounce = false
else
debounce = false
end
end
end)