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

Trying to add a gamepass script, argument 2 is missing or nil?

local gamepass = 5620181
local service = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:connect(function()
	if service:PlayerOwnsAsset(gamepass) then
		if script.Parent.Parent.Parent.TeleportGui.Enabled == false then
			script.Parent.Parent.Parent.TeleportGui.Enabled = true
		else
			script.Parent.Parent.Parent.TeleportGui.Enabled = false
		end
	end
end)

It's supposed to open a gui if the player owns the gamepass.

EDIT: Figured out that a few things had been changed. There's now no error whatsoever, but nothing happens when clicking the button

Here's the new script:

local passid = 5620181
local service = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:connect(function()
    if service:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, passid) then
        if script.Parent.Parent.Parent.TeleportGui.Enabled == false then
            script.Parent.Parent.Parent.TeleportGui.Enabled = true
        else
            script.Parent.Parent.Parent.TeleportGui.Enabled = false
        end
    end
end)

1 answer

Use a localscript and this script instead:


local gamepass = 5620181
local service = game:GetService("MarketplaceService")
 
script.Parent.MouseButton1Click:connect(function()
    if service:PlayerOwnsAsset(game.Players.LocalPlayer,gamepass) then
        if script.Parent.Parent.Parent.TeleportGui.Enabled == false then
            script.Parent.Parent.Parent.TeleportGui.Enabled = true
        else
            script.Parent.Parent.Parent.TeleportGui.Enabled = false
        end
    end
end)

3 comments

0

Hmm... I don't get the error anymore, but now nothing happens.

0

Try changing the fourth line with " if service:PlayerOwnsAsset(game.Players.LocalPlayer.UserId,gamepass) then " or

0

or this if service:PlayerOwnsAsset(game.Players.LocalPlayer,gamepass) == true then

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