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

Why is there an error with MarketplaceService:PlayerOwnsAsset() only in Roblox Player?

Hello! I have a Shop GUI that checks to see if the player owns the game pass, if so spawns the gear the player selected or prompts them to buy the game pass and shows an error GUI label. At first I had it in a normal script it worked fine in Studio but in game I get the error below.

MarketplaceService:PlayerOwnsAsset() player should be of type Player, but is of type nil

Then I realized that I needed to put it in a Local Script. When I did that It still works fine in studio but still does not work in game and now no message appears at all in server log.

Any help would be appreciated.

My Code (in a local script):

-- Made by WindNT
local passId = 485342977 -- change this to your game pass ID.
local tool = game.ServerStorage.SparkleTime
local plr = game.Players.LocalPlayer

function isAuthenticated(player) -- checks to see if the player owns your pass
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, passId)
end


script.Parent.MouseButton1Click:connect(function(player)
if isAuthenticated(plr) then --Has Game Pass
		tool:Clone().Parent = plr.Backpack
        print(plr.Name .. " has bought the game pass with id " .. passId)
else -- If not then Show error and prompt purchase
	--script.Parent.ClickDetector.MouseClick:connect(function(player) -- Prompt purchase
	game:GetService("MarketplaceService"):PromptPurchase(plr, passId)
--end)	
	--GUI MESSAGE
	
	--Clear GUI Message
	script.Parent.Parent.ErrorMessage.Visible = true
	wait(.2)
	script.Parent.Parent.ErrorMessage.Visible = false
	wait(.2)
	script.Parent.Parent.ErrorMessage.Visible = true
	wait(.2)
	script.Parent.Parent.ErrorMessage.Visible = false
	wait(.2)
	script.Parent.Parent.ErrorMessage.Visible = true
	wait(8)
	script.Parent.Parent.ErrorMessage.Visible = false
end

end)

1 comment

0

Thanks for your help, I ended up figuring out the issue. I had my tools is Server Storage not Lighting.

1 answer

✓ Accepted answer

MarketPlaceService does not work on the client for security reasons and MouseButton1Click does not give a player parameter

--line 11
script.Parent.MouseButton1Click:connect(function(player)

2 comments

0

Thanks for your quick response! What do you suggest to fix this issue?

0

i would do the same thing you are doing, but at the PlayerOwnsAsset part i would fire a remote event and from there check(sorry for late response)

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