Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
WindNT 16
7 years ago

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)
0
Thanks for your help, I ended up figuring out the issue. I had my tools is Server Storage not Lighting. WindNT 16 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)

0
Thanks for your quick response! What do you suggest to fix this issue? WindNT 16 — 7y
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) derpidogy 30 — 7y
Ad

Answer this question