Hi! So I made a gamepass that makes X2 coins but, I want to check if the player has the gamepass but I have to check that in another script here is the script (I used UserOwnsGamePassAsync but did not work)
local mps = game:GetService("MarketplaceService") local button = script.Parent local debounce = false local gamePassID = 9189975 button.Touched:Connect(function(hit) debounce = true if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player then return end if player then if player.Team.Name == "Red" then if mps:UserOwnsGamePassAsync(player, gamePassID) then player.leaderstats.Money.Value = player.leaderstats.Money.Value + button.Parent.Screen.MoneySaved.Value * 2 button.Parent.Screen.MoneySaved.Value = 0 debounce = false if debounce == false then button.BrickColor = BrickColor.new("Really red") wait(2) button.BrickColor = BrickColor.new("Sea green") end end end end end end)
I dont use UserOwnsGamePassAsync, what I use is
if mps:PlayerOwnsAsset(player, gamePassID) then
Also, you said
if player.Team.Name == "Red" then if mps:PlayerOwnsAsset(player, gamePassID) then
Instead Of
if player.Team.Name == "Red" and mps:PlayerOwnsAsset(player, gamePassID) then
Hopefully that helps, completed code using that method is
local mps = game:GetService("MarketplaceService") local button = script.Parent local debounce = false local gamePassID = 9189975 button.Touched:Connect(function(hit) debounce = true if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player then return end if player then if player.Team.Name == "Red" and mps:PlayerOwnsAsset(player, gamePassID) then player.leaderstats.Money.Value = player.leaderstats.Money.Value + button.Parent.Screen.MoneySaved.Value * 2 button.Parent.Screen.MoneySaved.Value = 0 debounce = false if debounce == false then button.BrickColor = BrickColor.new("Really red") wait(2) button.BrickColor = BrickColor.new("Sea green") end end end end end)
The built in function :UserOwnGamePassAsync is a way to show it a player has a gamepass.
Make sure it's in a local script Also if you want to grant your self something like a tool you must need a remote event since the local player cannot give tools to its back pack
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") -- Function to prompt purchase of the game pass local function promptPurchase() local player = Players.LocalPlayer local hasPass = false local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) -- checks to see if a player has a gamepass if not it will error button.Touched:Connect(function(hit) debounce = true if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player then return end if player then if player.Team.Name == "Red" then if hasPass then player.leaderstats.Money.Value = player.leaderstats.Money.Value + button.Parent.Screen.MoneySaved.Value * 2 button.Parent.Screen.MoneySaved.Value = 0 debounce = false if debounce == false then button.BrickColor = BrickColor.new("Really red") wait(2) button.BrickColor = BrickColor.new("Sea green") end end end end end end) end) if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass then end end end end end
local passId = 0000000 -- change this to your game pass ID. function isAuthenticated(player) -- checks to see if the player owns your pass return game:GetService("GamePassService"):PlayerHasPass(player, passId) -- this method will check to see if player has the pass from the passId end function Start(plr) print(plr.Name .. " has bought the game pass with id " .. passId) end game.Players.PlayerAdded:connect(function(plr) if isAuthenticated(plr) then -- checks to see if player is authenticaded Start(plr) -- activate function end end)
This is the code it's really easy