--------------------
--| 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 DebrisService = Game:GetService('Debris')

local Teleporter = script.Parent

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ExitPartObject = WaitForChild(script, 'ExitPart')

local JustTouched = {}

-----------------
--| Functions |--
-----------------

-- 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
				local character = player.Character
				if not character:FindFirstChild('JustTeleported') then
					local justTeleported = Instance.new('StringValue')
					justTeleported.Name = 'JustTeleported'
					DebrisService:AddItem(justTeleported, 0.3)
					justTeleported.Parent = character
					character:MoveTo(ExitPartObject.Value.Position)
				end
			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 |--
--------------------

Teleporter.Touched:connect(OnTouched)

while true do
	RemoveOldTouches()
	wait(1/30)
end

5 comments

0

Have you made an attempt yourself first?

0

This site isn't a service where you pay for fixing code. Is this even your code you attempted back then?

0

Second time you've broke the rule 4 of the website guidelines, 4. Do not offer rewards for answers to questions.

0

I really tried to solve it myself I am really desperate at this point. I am willing to pay for the effort and expertise of you guys. I am not trying to break any rule or anything. I can write a lot of things that I tried but I wanted to keep it short to not bore you all with all my failed amptempts

0

This is a qa site not a script for hire site.