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

Gamepass script not working?

Asked by
KenzaXI 166
8 years ago

The script is a localscript and is inside a Image button. the script is :

script.Parent.MouseButton1Click:connect(function(plr)
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,277976767) then
        local AS = game.Lighting["atlas sword"]:Clone().Parent == plr.Backpack
    end
end)

I don't get why it won't work, Because the output says: "MarketplaceService:PlayerOwnsAsset() player should be of type Player, but is of type nil" Thanks for the help.

1 answer

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
8 years ago

The event MouseButton1Click does not have a parameter of the player. If you want to access the player, use game.Players.LocalPlayer since you are using a LocalScript (LocalPlayer does not work in a regular Script).

Also on line 3, == is used for comparison. You are actually parenting the tool to the player's Backpack, so you would use =. You would also not create a variable for it since you are actually doing the action.


Fixed Code:

local player = game.Players.LocalPlayer --This is the player.

script.Parent.MouseButton1Click:connect(function()
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,277976767) then
        game.Lighting["atlas sword"]:Clone().Parent = player.Backpack
    end
end)

Here is the Wiki page on LocalPlayer.

If I helped you out, be sure to accept my answer!

0
Cheers KenzaXI 166 — 8y
Ad

Answer this question