`ID = 154872414 Door = script.Parent Door.Touched:connect(function(hit) if hit.Parent.Humanoid then -- 1 Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- 2 if game:GetService("GamePassService"):PlayerHasPass(Player, ID) then -- 3 script.Parent.CanCollide = false -- 4 script.Parent.Transparency = 0.5 wait(2) script.Parent.CanCollide = true script.Parent.Transparency = 0 end end end)
--1 Checks whether the part that touched the door is human or not. However, there is the issue with hats.. the event disconnects if the part was a hat. --2 If the part is part of a human, it gets the player from the part's parent, which is the character model. --3 If the player has the pass.. --4 Then the player can walk through the door. I'd suggest making the character teleport, though, if you don't want others mooching of the player with the pass`I tried one of your and it didn't work out so can you help me! here what I tried! and do a working one if they work and doesn't work anymore!
-- 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
local GamePassService = game:GetService('GamePassService') local PlayersService = game:GetService('Players')
local VipDoor = script.Parent
local GamePassIdObject = WaitForChild(script, 'GamePassId')
local JustTouched = {}
-- 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:PlayerHasPass(player, 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
VipDoor.Touched:connect(OnTouched)
while true do RemoveOldTouches() wait(1/30) end
First: Create A Part Called "VIP Door" Then put a script inside the part and name the script "VIP Door" Lastly put an IntValue inside the script.
The Value of the IntValue should be your gamepass id.
The coding in the script should be as follows:
Please Note: To easily get this door, go to studio -> Toolbox -> ROBLOX SETS -> Game Pass: VIP Door
-------------------- --| 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('GamePassService') local PlayersService = game:GetService('Players') local VipDoor = script.Parent local GamePassIdObject = WaitForChild(script, '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:PlayerHasPass(player, 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