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

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

Asked by 6 years ago

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)
0
sooooooooo you think code can read your mind and know what player you wanna check? hiimgoodpack 2009 — 6y
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. Netflixy 126 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

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)
0
accept my answer if this helped please creeperhunter76 554 — 6y
0
Oh hai creeper SmugNyan 24 — 6y
Ad
Log in to vote
0
Answered by
CootKitty 311 Moderation Voter
6 years ago

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)
0
Thanks. FreakingHulk 0 — 6y
0
It's still saying Argument 2 is missing or nil FreakingHulk 0 — 6y
0
:connect is deprecated, get into the habit of using :Connect awfulszn 394 — 6y

Answer this question