Touch a part and teleport to another position help

im trying to make an elevator that when a player goes inside they will wait the cooldown. when the cooldown ends that player and anyone else inside elavator teleports to main game. i hope i was able to explain enough in the script’

local teleportToGame = script.Parent.Parent:WaitForChild("Part") -- Part that covers entire elevator and will be used to tell if a player is touching it so if they decide to leave it doesnt tp them
local leaving = script.Parent.Parent:WaitForChild("Leaving") -- part with surface gui inside 
local SurfaceGui = leaving.SurfaceGui:WaitForChild("TextLabel") -- the text label inside the surface gui
local debounce = false
script.Parent.Touched:Connect(function(hit) --script.parent is the part they touch to tp inside the elevator (its located on the outside)
	if debounce then
		return
	end
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-11, 3, -140.373) --the middle part of the elevator
		warn("Teleported")
		game.StarterGui.Playergui.Leave.Visible = true --the text button that gives them option to leave (im planning on using replicated storage later)
		debounce = true
		SurfaceGui.Text = "Leaving In: 30" --sorry im not good with loops :(
		wait(1)
		SurfaceGui.Text = "Leaving In: 29"
		wait(1)
		SurfaceGui.Text = "Leaving In: 28"
		wait(1)
		SurfaceGui.Text = "Leaving In: 27"
		wait(1)
		SurfaceGui.Text = "Leaving In: 26"
		wait(1)
		SurfaceGui.Text = "Leaving In: 25"
		wait(1)
		SurfaceGui.Text = "Leaving In: 24"
		wait(1)
		SurfaceGui.Text = "Leaving In: 23"
		wait(1)
		SurfaceGui.Text = "Leaving In: 22"
		wait(1)
		SurfaceGui.Text = "Leaving In: 21"
		wait(1)
		SurfaceGui.Text = "Leaving In: 20"
		wait(1)
		SurfaceGui.Text = "Leaving In: 19"
		wait(1)
		SurfaceGui.Text = "Leaving In: 18"
		wait(1)
		SurfaceGui.Text = "Leaving In: 17"
		wait(1)
		SurfaceGui.Text = "Leaving In: 16"
		wait(1)
		SurfaceGui.Text = "Leaving In: 15"
		wait(1)
		SurfaceGui.Text = "Leaving In: 14"
		wait(1)
		SurfaceGui.Text = "Leaving In: 13"
		wait(1)
		SurfaceGui.Text = "Leaving In: 12"
		wait(1)
		SurfaceGui.Text = "Leaving In: 11"
		wait(1)
		SurfaceGui.Text = "Leaving In: 10"
		wait(1)
		SurfaceGui.Text = "Leaving In: 9"
		wait(1)
		SurfaceGui.Text = "Leaving In: 8"
		wait(1)
		SurfaceGui.Text = "Leaving In: 7"
		wait(1)
		SurfaceGui.Text = "Leaving In: 6"
		wait(1)
		SurfaceGui.Text = "Leaving In: 5"
		wait(1)
		SurfaceGui.Text = "Leaving In: 4"
		wait(1)
		SurfaceGui.Text = "Leaving In: 3"
		wait(1)
		SurfaceGui.Text = "Leaving In: 2"
		wait(1)
		SurfaceGui.Text = "Leaving In: 1"
		wait(1)
		SurfaceGui.Text = "Loading..."
		wait(1)
		SurfaceGui.Text = "Loading.."
		wait(1)
		SurfaceGui.Text = "Loading."
		wait(1)
		SurfaceGui.Text = "Loading..."--fake loading screen
		wait(1)
		teleportToGame.Touched:Connect(function(hit)  --after the loading ends make the part covering inside elevator tp anyone ttouching it
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-460.4, 6, -6.3) --position of game
				warn("TeleportedToGame")
			else 
					warn("ERROR") --if all else goes wronge
				end
		end)
	end
end)

if the script isnt enough access this model:

you will have to get rid of the part where i make the leave button visible though.

side note if anyone wants to work on game with my ill be happy to accept you <3

2 Likes

to teleport the character do

hit.Parent:MoveTo(positionhere)

1 Like

so

local teleportToGame = script.Parent.Parent:WaitForChild("Part") -- Part that covers entire elevator and will be used to tell if a player is touching it so if they decide to leave it doesnt tp them
local leaving = script.Parent.Parent:WaitForChild("Leaving") -- part with surface gui inside 
local SurfaceGui = leaving.SurfaceGui:WaitForChild("TextLabel") -- the text label inside the surface gui
local debounce = false
script.Parent.Touched:Connect(function(hit) --script.parent is the part they touch to tp inside the elevator (its located on the outside)
	if debounce then
		return
	end
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-11, 3, -140.373) --the middle part of the elevator
		warn("Teleported")
		game.StarterGui.Playergui.Leave.Visible = true --the text button that gives them option to leave (im planning on using replicated storage later)
		debounce = true
		SurfaceGui.Text = "Leaving In: 30" --sorry im not good with loops :(
		wait(1)
		SurfaceGui.Text = "Leaving In: 29"
		wait(1)
		SurfaceGui.Text = "Leaving In: 28"
		wait(1)
		SurfaceGui.Text = "Leaving In: 27"
		wait(1)
		SurfaceGui.Text = "Leaving In: 26"
		wait(1)
		SurfaceGui.Text = "Leaving In: 25"
		wait(1)
		SurfaceGui.Text = "Leaving In: 24"
		wait(1)
		SurfaceGui.Text = "Leaving In: 23"
		wait(1)
		SurfaceGui.Text = "Leaving In: 22"
		wait(1)
		SurfaceGui.Text = "Leaving In: 21"
		wait(1)
		SurfaceGui.Text = "Leaving In: 20"
		wait(1)
		SurfaceGui.Text = "Leaving In: 19"
		wait(1)
		SurfaceGui.Text = "Leaving In: 18"
		wait(1)
		SurfaceGui.Text = "Leaving In: 17"
		wait(1)
		SurfaceGui.Text = "Leaving In: 16"
		wait(1)
		SurfaceGui.Text = "Leaving In: 15"
		wait(1)
		SurfaceGui.Text = "Leaving In: 14"
		wait(1)
		SurfaceGui.Text = "Leaving In: 13"
		wait(1)
		SurfaceGui.Text = "Leaving In: 12"
		wait(1)
		SurfaceGui.Text = "Leaving In: 11"
		wait(1)
		SurfaceGui.Text = "Leaving In: 10"
		wait(1)
		SurfaceGui.Text = "Leaving In: 9"
		wait(1)
		SurfaceGui.Text = "Leaving In: 8"
		wait(1)
		SurfaceGui.Text = "Leaving In: 7"
		wait(1)
		SurfaceGui.Text = "Leaving In: 6"
		wait(1)
		SurfaceGui.Text = "Leaving In: 5"
		wait(1)
		SurfaceGui.Text = "Leaving In: 4"
		wait(1)
		SurfaceGui.Text = "Leaving In: 3"
		wait(1)
		SurfaceGui.Text = "Leaving In: 2"
		wait(1)
		SurfaceGui.Text = "Leaving In: 1"
		wait(1)
		SurfaceGui.Text = "Loading..."
		wait(1)
		SurfaceGui.Text = "Loading.."
		wait(1)
		SurfaceGui.Text = "Loading."
		wait(1)
		SurfaceGui.Text = "Loading..."--fake loading screen
		wait(1)
		teleportToGame.Touched:Connect(function(hit)  --after the loading ends make the part covering inside elevator tp anyone ttouching it
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent:MoveTo(-460.4, 6, -6.3)  --position of game
				warn("TeleportedToGame")
			else 
					warn("ERROR") --if all else goes wronge
				end
		end)
	end
end)

yeah should work also your script is unessesarely long

1 Like

it didnt work. can you rewrite it? also if you want to play the game to see for yourself

https://www.roblox.com/games/8320839596/Hostility

1 Like

edit: im just sitting in an elevator and the tp isnt teleporting me to game when load ends (the issue is at end of script near when i teleport player to game

1 Like

When you’re talking about teleporting to the game do you mean as in a position thing like a minigame within the same experience? Or do you mean like a camping game teleport that’s transfer you into a different experience?

1 Like

yes a minigame in the experience.

1 Like

ok i found the issue is for some reason then touched area isnt even registering the player touching it (at end of script when the loading ends)

1 Like

ah i rescripted the whole thing then u found the solution

oh well here it is anyways, might not be the best way to approach it and also might not even work but here

local teleportToGame = script.Parent.Parent:WaitForChild("Part")
local leaving = script.Parent.Parent:WaitForChild("Leaving")
local SurfaceGui = leaving.SurfaceGui:WaitForChild("TextLabel")
local debounce = false

local Timer = 30
local IsLoaded = false

script.Parent.Touched:Connect(function(hit)
   if debounce == false then
   	if hit.Parent:FindFirstChild("Humanoid") then
   		
   		hit.Parent:MoveTo(-11, 3, -140.373)
   		print("Teleported")
   		
   		game.StarterGui.Playergui.Leave.Visible = true
   		debounce = true
   		
   		
   		while task.wait(1) do
   			
   			if Timer <= 30 and Timer >= 1 then
   				Timer -= 1
   				SurfaceGui.Text = "Leaving in: " .. Timer
   			elseif Timer < 1 then
   				SurfaceGui.Text = "Loading..."
   				wait(3)
   				IsLoaded = true
   			end
   		end
   	end
   end
end)

teleportToGame.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") and IsLoaded == true then
   	hit.Parent:MoveTo(-460.4, 6, -6.3)  --position of game
   	print("TeleportedToGame")
   end
end)
1 Like

hey why is it erroring

Unable to cast double to Vector3

i didnt even know that was an error

oh just remove the decimal numbers in the teleport parts

so instead of like 405.41 or something just make it 405

wait no im dumb try this

local teleportToGame = script.Parent.Parent:WaitForChild("Part")
local leaving = script.Parent.Parent:WaitForChild("Leaving")
local SurfaceGui = leaving.SurfaceGui:WaitForChild("TextLabel")
local debounce = false

local Timer = 30
local IsLoaded = false

script.Parent.Touched:Connect(function(hit)
   if debounce == false then
   	if hit.Parent:FindFirstChild("Humanoid") then
   		
   		hit.Parent:MoveTo(Vector3.new(-11, 3, -140))
   		print("Teleported")
   		
   		game.StarterGui.Playergui.Leave.Visible = true
   		debounce = true
   		
   		
   		while task.wait(1) do
   			
   			if Timer <= 30 and Timer >= 1 then
   				Timer -= 1
   				SurfaceGui.Text = "Leaving in: " .. Timer
   			elseif Timer < 1 then
   				SurfaceGui.Text = "Loading..."
   				wait(3)
   				IsLoaded = true
   			end
   		end
   	end
   end
end)

teleportToGame.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") and IsLoaded == true then
   	hit.Parent:MoveTo(Vector3.new(-460, 6, -6))  --position of game
   	print("TeleportedToGame")
   end
end)

same error ocuring. maybe MoveTo: doesnt work? we could try position = vector3.new() instead

or maybe its position = MoveTo()

(and to note this error is occuring when i try to tp inside the elevator. before loading starts)

no moveto() should work idk, you said you found the sollution so you could also just try out ur old script sorr for wasting urtime

1 Like

i didnt find the solution though. the old script didnt work and this one isnt as well. were close though

i replaced Move:To with Cframe and im getting same problem as before but its working 50/50

by the way the part that is teleporting the player is already being touched by the player. can i do that? maybe thats the error

is it possible that i cant teleport somone multiple times in a script?

i got it working. i made it so instead of teleporting the player it now enables a script inside the touch part

Apparently the loop doesn’t stop.

   		while task.wait(1) and IsLoaded == false do
   			
   			if Timer <= 30 and Timer >= 1 then
   				Timer -= 1
   				SurfaceGui.Text = "Leaving in: " .. Timer
   			elseif Timer < 1 then
   				SurfaceGui.Text = "Loading..."
   				wait(3)
   				IsLoaded = true
   			end
   		end

or also:

	while task.wait(1) do
		
		if Timer <= 30 and Timer >= 1 then
			Timer -= 1
			SurfaceGui.Text = "Leaving in: " .. Timer
		elseif Timer < 1 then
			SurfaceGui.Text = "Loading..."
			wait(3)
			IsLoaded = true
			return
		end
	end