Advertisement
Benjinanas

Script PuertaVIP

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