Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I make a gamepass only building?

Asked by 5 years ago

I want to make a gamepass only building that will block players if they don't have the gamepass. If they have the gamepass, it will teleport them in or they will be able to walk through. If they don't have the gamepass, it will block them and not teleport them and also ask to buy the gamepass. How do I do this?

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Hello! Try this script. Make sure to put it as a normal script under the part that you want a player to touch to enter the building. Also, change the variable gamepassId to your gamepass's ID! Set the CFrame.new(x,y,z) on line 8 to the xyz position you want the player to be teleported to.

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 5433172 -- IMPORTANT: Replace this with your gamepass's ID!

script.Parent.Touched:Connect(function(touchedBy)
    if touchedBy.Parent:FindFirstChild("Humanoid") ~= nil then
        local ownsPass = MarketplaceService:UserOwnsGamePassAsync(game.Players[touchedBy.Parent.Name].UserId, gamepassId)
        if ownsPass then
            touchedBy.Parent:MoveTo(Vector3.new(0,0,0))
        end
    end
end)

If you have issues with this, please let me know!

1
:MoveTo(Vector3.new(0,0,0)) would be useful in this situation EmbeddedHorror 299 — 5y
0
Thank you, will edit my code to use :MoveTo(Vector3.new(0,0,0)) now. hpenney2 53 — 5y
0
Thanks so much! It worked! Will credit youin my game. Bssiemeow 30 — 5y
Ad

Answer this question