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:
1 | local passID = 695948228 |
2 | local gamepass = game:GetService( "GamePassService" ) |
3 |
4 | game.Players.PlayerAdded:connect( function (player, passID) |
5 | if gamepass:PlayerHasPass(passID) then |
6 | print (player.Name.. " owns the gamepass with the id of " ..passID) |
7 | game.ServerStorage.LaserShotGun:Clone(player.Backpack) |
8 | end |
9 | end ) |
The PlayerHasPass()
method, requires two arguments. the Player and the GamePass ID
Therefore, the fixed script would be
1 | local passID = 695948228 |
2 | local gamepass = game:GetService( "GamePassService" ) |
3 |
4 | game.Players.PlayerAdded:connect( function (player) |
5 | if gamepass:PlayerHasPass(player, passID) then -- invokes method with both required arguments |
6 | print (player.Name.. " owns the gamepass with the id of " ..passID) |
7 | game.ServerStorage.LaserShotGun:Clone().Parent = player.Backpack -- like CootKitty said, the Clone() method doesn't have any arguments |
8 | end |
9 | end ) |
You're over-righting the variable in the function to nil.
Also, Clone doesn't take arguments. You have to set the parent yourself.
1 | local passID = 695948228 |
2 | local gamepass = game:GetService( "GamePassService" ) |
3 |
4 | game.Players.PlayerAdded:connect( function (player) -- removed variable |
5 | if gamepass:PlayerHasPass(passID) then |
6 | print (player.Name.. " owns the gamepass with the id of " ..passID) |
7 | game.ServerStorage.LaserShotGun:Clone().Parent = player.Backpack -- changed |
8 | end |
9 | end ) |