The title explains it, I've tried to get somewhere but it doesn't appear to work, I'm making a basic little game where you click and it gives you points, blah blah blah, and for my effort of trying to make some profit I'm adding a gamepass which would increase your profits but I need help finding if a player has said gamepass. This isn't the entire script, but instead just the parts that relate to the gamepass and its function.
local UserId = game.Players.LocalPlayer.UserId
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 1
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(UserId, 8434678) then
player.leaderstats[currencyName].Value = player.leaderstats[currencyName].Value + 4
end
This is a normal script so I'm aware as to the fact that calling game.Players.LocalPlayer shouldn't work therefore I need some clearance as to how I should get the UserId.
(If it helps this game only runs servers with one player)

4 comments
game.Players.PlayerAdded:Connect(function(player) local userId = player.UserId end
Thanks but I ended up fixing it myself ^
Alright, no problem!
Put [SOLVED] in your title so other people know it's been solved.