How to give a gamepass owner Coins when they first join the game

Hello!

Can anyone help me in making a script that gives a gamepass owner a certain amount of Coins when they join the game and not get anymore even if they keep leaving and joining back.

I have an idea of using leaderstat values to make this, but I was wondering if there another way to do this?

If anyone can send some script examples of this for me to try it would be much appreciated and if anyone has any questions or wants to see the way I would do it - feel free to ask!

Thanks!!

You would use UserOwnsGamePassAsync

local MarketPlaceService = game:GetService("MarketPlaceService ")

local PlrOwns =  MarketPlaceService.UserOwnsGamePassAsync(Userid, GamePassiD)

if PlrOwns then
-- Give player coins
  
end

1 Like

Where it says GamePassiD, would I put the ID of my gamepass?

Yes, and Userid would be the players userid which you can get from the player.

https://developer.roblox.com/en-us/api-reference/property/Player/UserId

1 Like

Typing in the script and the Userid is underlined

you dont have to put any userId in this since the game can detect if you’re the owner by game.CreatorId

local YourGamePassId = 1 -- Change 1 to your gamepass ID

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

if plr.UserId ~= game.CreatorId then return end -- Checks if the Player Is The Owner if not it will not continue.

local GamePassCheck = game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(game.CreatorId,YourGamePassId)

if GamePassCheck then
-- stuff
else
warn("There Was An Error")
end
end)
1 Like

What if a normal player isn’t the game creator? That’s not really ideal.

he won’t get anything,
as @Treatmentfrom mentioned he said that he want only to check if the Game Owner has the gamepass

He meant to a gamepass owner, not place owner.

The game is created by a group, I am the only person who has access to the place but the game itself is published on a group. Will that affect anything such as the CreatorId?

do you want to check if any player have the gamepass or only the Creator?

I want to check if the player owns the gamepass, if they do, they get Coins upon joining

and yes that will affect it so in that case, you can check the owner’s Rank in the group, OR
you can just put his UserId by

local OwnerUserId = 1 -- Example
if plr.UserId == OwnerUserId then
-- stuff
end

then you can just do that

local YourGamePassId = 1 -- Change 1 to your gamepass ID

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

local GamePassCheck = game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(plr.UserId,YourGamePassId)

if GamePassCheck then
-- stuff
else
warn("There Was An Error")
end
end)
1 Like

Would this script be a normal script and be in ServerScriptService?

1 Like

yes insert a script into serverscriptservice [Char Limit]

1 Like

Here:

Paste this script in a Regular Script in ServerScriptService.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("MarketplaceService")

local passId = 000000 -- Change this to your gamepass ID


Players.PlayerAdded:Connect(function(player) -- This is the event that detects when a player joins
      local Coins = player.leaderstats.Coins.Value

     local hasReceived = Instance.new("BoolValue") -- Create a boolean value that determines whether the player has already earned the coins or not
     hasReceived.Parent = player
     hasReceived.Name = "hasReceived"
     hasReceived.Value = false


     if MarketplaceService:UserOwnsGamepassAsync(player.UserId, passId) and hasReceived.Value == false then
     
        player.leaderstats.Coins.Value += 50 -- Change the number to however many coins you want the player to receive.

    hasReceived.Value = true -- Sets the Boolean Value to true so the player will not receive the coins when they join again.
        
     end
end)

Won’t this script insert a bool value every time the player joins?
Even if the player leaves and rejoins it isn’t like the boolen value that was created last time will be there instead a new one will be created allowing the user to get coins by rejoining.

I think it would be better to use datastores as the value will be saved even if player rejoins.

1 Like

to add to that. you need to add a playeradded event before checking if the player owns the gamepass

No. If someone already has it then they won’t get a new one each time