Advertisement
Guest User

Code

a guest
Jun 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. -- TheRealRobin989, for the DOOR
  2. local function WaitForChild(parent, childName)
  3. assert(parent, "ERROR: WaitForChild: parent is nil")
  4. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  5. return parent[childName]
  6. end
  7. local GamePassService = game:GetService('MarketplaceService')
  8. local PlayersService = game:GetService('Players')
  9. local VipDoor = script.Parent
  10. local GamePassIdObject = WaitForChild(script, 'GamePassId')
  11. local JustTouched = {}
  12. local function TeleportToOtherSide(character, hitPart)
  13. local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
  14. local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
  15. local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3
  16.  
  17. local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
  18. local distanceToBack = (behindDoor - hitPart.Position).magnitude
  19. if distanceToFront < distanceToBack then
  20. character:MoveTo(behindDoor)
  21. else
  22. character:MoveTo(inFrontOfDoor)
  23. end
  24. end
  25. local function OnTouched(otherPart)
  26. if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
  27. local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
  28. if player and not JustTouched[player] then
  29. JustTouched[player] = time()
  30. if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then
  31. TeleportToOtherSide(player.Character, otherPart)
  32. else GamePassService:PromptGamePassPurchase(player, GamePassIdObject.Value)
  33. end
  34. end
  35. end
  36. end
  37. local function RemoveOldTouches()
  38. for player, touchTime in pairs(JustTouched) do
  39. if time() > touchTime + 0.3 then
  40. JustTouched[player] = nil
  41. end
  42. end
  43. end
  44. VipDoor.Touched:connect(OnTouched)
  45. while true do
  46. RemoveOldTouches()
  47. wait(1/30)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement