how would i make a door that opens when you buy a gamepass
heres the code i have so far
--
local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local doorPart = game.Workspace.Door.Door
local gamepassId = 44709053
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then
print("Player owns pass.")
doorPart.CanCollide = false
else
print("Player does not own pass.")
doorPart.CanCollide = true
end
Okay, from here, you need to check when the player touches the door, which can be done by using Part.Touched().
The issue with doors like this is if someone opens the door, somebody else can slip through and get past even if they don’t own it, there are two ways to prevent that.
1: Making the doors code all on the client, which could lead to hackers editing parts of it to abuse the system.
2: Making the door teleport you instead of letting you through, which is a lot more reliable compared to all of it being on the client.
You should connect to the marketplace function for seeing if a gamepasspurchase was made
-- you can setup the event on run time like this
local DoorEvent = Instance.new('RemoteEvent',game.ReplicatedStorage)
DoorEvent.Name = 'DoorEvent'
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player,gamePassId,wasPurchased)
if wasPurchased then
if gamePassId == 44709053 then
-- fire remote event to this Player's client to make door non collide
DoorEvent:FireClient(Player, 'OpenDoor') -- or something like this
end
end
end)