I’m trying to do dev products with touched event, if I local test it with 2 players and Player 1 touches the part this shows on Players 2 output: MarketplaceService:PromptProductPurchase called from a local script, but not called on a local player. Local scripts can only prompt the local player. Is this normal or did I something wrong?
This is the local script:
local mps = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Wins15 = game.Workspace.Part
Wins15.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
local plrs = Players:GetPlayerFromCharacter(hit.Parent)
mps:PromptProductPurchase(plrs, 1528483289)
end
end)
Its still the same outcome, output still says: MarketplaceService:PromptProductPurchase called from a local script, but not called on a local player. Local scripts can only prompt the local player.
Check if the touching part/character is Player2’s character, like this :
local mps = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Wins15 = game.Workspace.Part
Wins15.Touched:Connect(function(hit)
if not hit or not hit.Parent:FindFirstChild("Humanoid") then return end
local plrs = Players:GetPlayerFromCharacter(hit.Parent)
if plrs ~= Players.LocalPlayer then return end
mps:PromptProductPurchase(plrs, 1528483289)
end)
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Wins15 = game.Workspace.Part
Wins15.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
local plr = Players:GetPlayerFromCharacter(hit.Parent)
if Players.LocalPlayer == plr then
MPS:PromptProductPurchase(plr, 1528483289)
end
end
end)
also actually the more ends are there the easier it is to manipulate the scripts, usually i type 200 lines per day. so i use lots of ends because i use lots of If statements or loops or functions, it helps everything to look easier and understand unknown scripts if you’re working in a commission or smth.
I know, however guard clauses is a technique that can be used in many scenarios. say if you forgot to send parameters for a function as in below.
function FunctionThatPrints(whatToPrint)
-- Stops the function from running unless "whatToPrint" is passed to the function
if not whatToPrint then return end
-- This will not run, as the check above stops it from doing so.
print(`coolswag {whatToPrint}`)
end
However, if you prefer you can still write is as
function FunctionThatPrints(whatToPrint)
if whatToPrint then
print(`coolswag {whatToPrint})
end
end