I need help with a gamepass door! I want it to check if the player owns this gamepass ID: 9980019, if he doesn’t the door should do a promptpurchase to the player for that gamepass. But I need help, answers are appreciated!
Use MarketplaceService and :UserOwnsGamePassAsync() to check for this.
local mps = game:GetService("MarketplaceService") local gamepassId = 9980019 local door = script.Parent door.Touched:Connect(function(part) if part.Parent:FindFirstChildWhichIsA("Humanoid") then local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent) local userId = plr.UserId if mps:UserOwnsGamePassAsync(userId, gamepassId) then --Run code if player owns the gamepass else mps:PromptGamePassPurchase(plr, gamepassId) end end end)
This is just an example of how to achieve what you want to do, change the code to fit your games needs.
Should I put this inside a script, and this script inside the door?
You can call the methods from MarketplaceService UserOwnsGamepassAsync and PromptPurchase to achieve what you want.
This method is called with 2 arguments, the player’s UserId and the GamepassId. It returns whether or not the player owns the gamepass and this is what you should be calling in an if-statement that if fails, will call the second method listed below.
This method prompts a purchase as the name states and is called with 2 required arguments, the Player (instance) and the AssetId, and can also be called with 2 more after that, a boolean that tells the service to equip the gamepass for the player and the currencytype.
Using these two methods you should be able to write a script to open and close the door. If you don’t already know how to achieve the actual door opening affect the simplest way is to just set the CanCollide property of the door’s part’s to false on the client.
You shouldn’t feed people like this. If you do this, they learns nothing. You may help him, but giving the actual code isn’t okay.
@CriticCritic Umm… Can I ask why you put WhichIsA behind FindFirstChild?
It finds the first child which has the ClassName specified. This causes the script to not try to find “player” from a moving part that hit the door.
:FindFirstChildOfClass(“Humanoid”) could also be used.