Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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('MarketplaceService')
- local PlayersService = game:GetService('Players')
- local PuertaVIP = script.Parent
- local GamePassIdObject = script:WaitForChild( 'GamepassID')
- local JustTouched = {}
- local function TeleportToOtherSide(character, hitPart)
- local bottomOfDoor = PuertaVIP.CFrame.p - Vector3.new(0, PuertaVIP.Size.Y / 2, 0)
- local inFrontOfDoor = bottomOfDoor + PuertaVIP.CFrame.lookVector * 3
- local behindDoor = bottomOfDoor - PuertaVIP.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
- 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
- local function RemoveOldTouches()
- for player, touchTime in pairs(JustTouched) do
- if time() > touchTime + 0.3 then
- JustTouched[player] = nil
- end
- end
- end
- PuertaVIP.Touched:connect(OnTouched)
- while true do
- RemoveOldTouches()
- wait(1/30)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement