I have a gamepass as follows:
local player = game:GetService("Players")
local id = Here is my gamepass id
local ownsGamepass2x = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id)
game.ReplicatedStorage.GiveCoins.OnServerEvent:Connect(function(X, player)
if ownsGamepass2x then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 2
else
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
end
end)
So as you can see, if the player owns the game pass, then we want to give them 2 coins and if they don't, then we want to give them 1 coin.
On line 3, UserOwnsGamePassAsync take the player.UserId. But I can't get the player. The output is saying attempt to index nil with UserId.
I can't use game.Players.LocalPlayer because this is a script which check if the user owns the gamepass and not a local script.
How can I go about finding the player so I can get the player.UserId?
Thanks for any help

3 comments
well then make it a localscript.
The first variable in any remoteevent function to the server is the player. That means that X, is infact- the player. Try using X instead
@marinhren Thanks. It worked!