Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. --------------------
  2. --| WaitForChild |--
  3. --------------------
  4.  
  5. -- Waits for parent.child to exist, then returns it
  6. local function WaitForChild(parent, childName)
  7. assert(parent, "ERROR: WaitForChild: parent is nil")
  8. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  9. return parent[childName]
  10. end
  11.  
  12. -----------------
  13. --| Variables |--
  14. -----------------
  15.  
  16. local GamePassService = Game:GetService('GamePassService')
  17. local PlayersService = Game:GetService('Players')
  18. local DebrisService = Game:GetService('Debris')
  19.  
  20. local Teleporter = script.Parent
  21.  
  22. local GamePassIdObject = WaitForChild(script, 'GamePassId')
  23. local ExitLocationObject = WaitForChild(script, 'ExitLocation')
  24.  
  25. local JustTouched = {}
  26.  
  27. -----------------
  28. --| Functions |--
  29. -----------------
  30.  
  31. -- When a player with the game pass touches the door, teleport them to the other side
  32. local function OnTouched(otherPart)
  33. if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
  34. local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
  35. if player and not JustTouched[player] then
  36. JustTouched[player] = time()
  37. if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
  38. local character = player.Character
  39. if not character:FindFirstChild('JustTeleported') then
  40. local justTeleported = Instance.new('StringValue')
  41. justTeleported.Name = 'JustTeleported'
  42. DebrisService:AddItem(justTeleported, 0.3)
  43. justTeleported.Parent = character
  44. character:MoveTo(ExitLocationObject.Value)
  45. end
  46. end
  47. end
  48. end
  49. end
  50.  
  51. -- Removes old entries in JustTouched
  52. local function RemoveOldTouches()
  53. for player, touchTime in pairs(JustTouched) do
  54. if time() > touchTime + 0.3 then
  55. JustTouched[player] = nil
  56. end
  57. end
  58. end
  59.  
  60. --------------------
  61. --| Script Logic |--
  62. --------------------
  63.  
  64. Teleporter.Touched:connect(OnTouched)
  65.  
  66. while true do
  67. RemoveOldTouches()
  68. wait(1/30)
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement