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

How do I make door that only players with a specific gamepass can open?

Asked by 4 years ago

I need to make a script so that when a door is touched and the player has the Game Pass, the door will open for a few seconds before closing! How can I do this?

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

Ok, here's how to make a specific game pass door.

Firstly, make a game, and secondly, do a gamepass.

Here's the tutorial that tells you how to do a gamepass.

How to do a gamepass:

You must publish your game to the ROBLOX first (Shortcut key: ALT + P), then go to the ROBLOX website, press 'Create', the 'Create' button is on the ROBLOX website top. Once you opened the 'Create', find the game you want, and then press the settings button. Now, press 'Create Game Pass'. Insert images, type the game pass title and the description inside.

When you're done, press upload, and go back to your ROBLOX studio, open 'View', and then click on 'Game Explorer'. And check out are the gamepass was inside there (You can check it in Developers Product)! If that doesn't appear anything there, reopen the ROBLOX studio.

Ok, when you inserted them inside, insert this script:

(It might be very long lol)

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
    return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')

local VipDoor = script.Parent

local GamePassIdObject = script:WaitForChild( 'GamePassId')

local JustTouched = {}

-----------------
--| Functions |--
-----------------

-- Finds out which side the player is on and teleports them to the other
local function TeleportToOtherSide(character, hitPart)
    local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
    local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
    local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3

    local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
    local distanceToBack = (behindDoor - hitPart.Position).magnitude
    if distanceToFront < distanceToBack then
        character:MoveTo(behindDoor)
    else
        character:MoveTo(inFrontOfDoor)
    end
end

-- When a player with the game pass touches the door, teleport them to the other side
local function OnTouched(otherPart)
    if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
        local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
        if player and not JustTouched[player] then
            JustTouched[player] = time()
            if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then
                TeleportToOtherSide(player.Character, otherPart)
            end
        end
    end
end

-- Removes old entries in JustTouched
local function RemoveOldTouches()
    for player, touchTime in pairs(JustTouched) do
        if time() > touchTime + 0.3 then
            JustTouched[player] = nil
        end
    end
end

--------------------
--| Script Logic |--
--------------------

VipDoor.Touched:connect(OnTouched)

while true do
    RemoveOldTouches()
    wait(1/30)
end
-- (Finally, I done the script) 

-- PLEASE DON'T CHANGE ANYTHING IN SCRIPT.

-- Credits go to MonstroMaster. I don't own this thing. Thanks.

When you inserted the script inside, insert an IntValue into the game!

Make the IntValue was parented by the script, and then make the IntValue's value become yours gamepass ID!

You can copy the gamepass ID by going to the Game Explorer > Developers Products > YOUR GAMEPASS NAME > Right click on YOUR GAMEPASS NAME > Copy the ID!

Remember, I don't own this thing, but I also glad to help too!

Please mark this as an answer if that's work on you! Cyaaa~~

(I typed so long so nvm upvote please lol, and sorry for my grammar problem)

(bonus: I upvoted)

Ad

Answer this question