Problem with GamePass and leaderstats

Hello developers,

I made a script that want to reward a Player if he/she owns the gamepass. The function of it is to get “Starters Money” In-Game. I made a script for it.

local groupID = 10790270
local gamepassID = 18107316

local MPS = game:GetService(“MarketplaceService”)

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new(“Folder”)
leaderstats.Parent = player
leaderstats.Name = “leaderstats”

local Coins = Instance.new(“IntValue”)
Coins.Name = “Coins”
Coins.Parent = leaderstats
Coins.Value = 0

– Group Members Reward
if player:IsInGroup(groupID) then

  player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100

– Starters Money Gamepass
if player:OwnsGamePassAsync(player.UserId,gamepassID) then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 500
end
end
end)

I hope someone can help me.

Greetings!

You could just reference the conditional checks as their own statements, you don’t need to check if both the Player is in the group & checking for the gamepass as well if that’s what you mean?

local groupID = 10790270
local gamepassID = 18107316

local MPS = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    leaderstats.Name = "leaderstats"

    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Parent = leaderstats
    Coins.Value = 0

    --Group Members Reward
    if player:IsInGroup(groupID) then
       player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100
    end

    --Starters Money Gamepass
    if MPS:UserOwnsGamePassAsync(player.UserId,gamepassID) then
        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 500
    end
end)

Edit: WAIT A SECOND “OwnsGamePassAsync” IS NOT VALID, TRY THIS INSTEAD

The parent of leaderstats is invalid I think, cause there is no local called player.

Nah that wouldn’t be the case, PlayerAdded gives a parameter that is actually the Player instance that joined the game

If I put this in a server script, this would be valid:

game.Players.PlayerAdded:Connect(function(Player)
    print(Player.Name) --Prints "Jackscarlett"
end)

Okay, so i made a local for the check if the player owns the gamepass, but there is a new error:

I just realized that the moment I went to edit my post lol

Try again, I edited it this time

It worked! thanks. :grin: I made your comment a solution!