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

Gamepass script not working?

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

✓ Accepted answer

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!

1 comment

0

Cheers

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