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

Can someone help? this if statement is correct, but I'm getting 'Argument 2 missing or nil'

This is my code that clones a tool, and puts it in the player's backpack if they own a gamepass. Here it is m8s:

local passID = 695948228
local gamepass = game:GetService("GamePassService")
 
game.Players.PlayerAdded:connect(function(player, passID)
if gamepass:PlayerHasPass(passID) then
		print(player.Name.. " owns the gamepass with the id of " ..passID)
		game.ServerStorage.LaserShotGun:Clone(player.Backpack)
	end
end)

2 comments

0

sooooooooo you think code can read your mind and know what player you wanna check?

0

You don't specify which player to check if has the gamepass. You should use  :PlayerHasPass(player, passID). Also take a look at CootKitty's answer for other fixes.

2 answers

The PlayerHasPass() method, requires two arguments. the Player and the GamePass ID Therefore, the fixed script would be

local passID = 695948228
local gamepass = game:GetService("GamePassService")

game.Players.PlayerAdded:connect(function(player)
    if gamepass:PlayerHasPass(player, passID) then -- invokes method with both required arguments
        print(player.Name.. " owns the gamepass with the id of " ..passID)
        game.ServerStorage.LaserShotGun:Clone().Parent = player.Backpack -- like CootKitty said, the Clone() method doesn't have any arguments
    end
end)

2 comments

0

accept my answer if this helped please

0

Oh hai creeper

You're over-righting the variable in the function to nil.

Also, Clone doesn't take arguments. You have to set the parent yourself.

local passID = 695948228
local gamepass = game:GetService("GamePassService")

game.Players.PlayerAdded:connect(function(player) -- removed variable
    if gamepass:PlayerHasPass(passID) then
        print(player.Name.. " owns the gamepass with the id of " ..passID)
        game.ServerStorage.LaserShotGun:Clone().Parent = player.Backpack -- changed
    end
end)

3 comments

0

Thanks.

0

It's still saying Argument 2 is missing or nil

0

:connect is deprecated, get into the habit of using :Connect

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