Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

MarketplaceService Error "arguement 2 missing or nil"?

I copied this from developer.roblox.com and somehow it is not working. Help?

LocalScript:

local event = game.ReplicatedStorage.Remote:WaitForChild("Purchase")
script.Parent.MouseButton1Click:Connect(function(player)
	event:FireServer(player, 1125490296)
end)

Script:

local MarketplaceService = game:GetService("MarketplaceService")
local purchase = game.ReplicatedStorage.Remote:WaitForChild("Purchase")
purchase.OnServerEvent:Connect(function(player, id)
	MarketplaceService:PromptProductPurchase(player, id)
end)

Output Error:

  12:58:57.784  Argument 2 missing or nil  -  Server  -  Purchase:4
  12:58:57.785  Stack Begin  -  Studio
  12:58:57.785  Script 'ServerScriptService.Purchase', 4  -  Studio  -  Main:105
  12:58:57.785  Stack End  -  Studio

How?

5 comments

0

you can just do this from a local script

0

but won't it only show up on the client and not on the server?

0

what are you tryna do?

0

if you want to make a player purchase something then you can use a local script

0

its a dev product i want to add it on the server because if you add coins on the client its only visual not real

2 answers

✓ Accepted answer

In a RemoteEvent or RemoteFunction, the server receives the LocalPlayer that sent the request. The LocalScript should be this:

local event = game.ReplicatedStorage.Remote:WaitForChild("Purchase")
script.Parent.MouseButton1Click:Connect(function()
    event:FireServer(1125490296)
end)

If you are using a PromptProductPurchase on other people other then the LocalPlayer, the Script, not the LocalScript, should be this:

local MarketplaceService = game:GetService("MarketplaceService")
local purchase = game.ReplicatedStorage.Remote:WaitForChild("Purchase")
purchase.OnServerEvent:Connect(function(localPlayer, player, id)
    MarketplaceService:PromptProductPurchase(player, id)
end)

Since ur hot babe i decided to drop this amazing answer, when firing RemoteEvents, the player that fired it is automatically defined so for example when firing remote like this:

MyRemote:FireServer()

Server receives this:

MyRemote.OnServerEvent:Connect(function(Player)
	print(Player) -- automatically defined
end)

So in your case you are firing the Player as the first argument which in your case is nil because MouseButton1Click does not return anything (But i am not sure, maybe it does). But since client is auto defined, all you have to do is remove the client as first argument in the local script, so LocalScript:

local event = game.ReplicatedStorage.Remote:WaitForChild("Purchase")
script.Parent.MouseButton1Click:Connect(function()
    event:FireServer(1125490296)
end)

and the Server will receive:

local MarketplaceService = game:GetService("MarketplaceService")
local purchase = game.ReplicatedStorage.Remote:WaitForChild("Purchase")
purchase.OnServerEvent:Connect(function(player, id)
    MarketplaceService:PromptProductPurchase(player, id)
end)

Also i noticed you use WaitForChild on the remote event but the thing is that all instances in ReplicatedStorage replicate before any script runs so you can remove that if the remote is created in editor.

yeah and ur done

click for robux

This discussion is preserved as it was. New answers, comments, and votes are closed.