Is there anyway I can make this script preform faster

Hey, I made a teleport script that teleports you to a place. And when testing it I noticed that it is really slow. (Sidenote: for those that do not know you cannot test TeleportServices in Roblox Studio) Is there any way I can fix it or atleast make it teleport the second someone touches the part?
Thanks!

-- Services to use in the code.
local teleportService = game:GetService('TeleportService')
local players = game:GetService('Players')

-- The place you are teleporting the player.
local targetPlace =     ---id for the place I want to teleport

script.Parent.Touched:Connect(function(hit)
	-- Most of this is from the official dev wiki.
	local player = players:GetPlayerFromCharacter(hit.Parent)
	
	-- Making sure the player exists.
	if player then	
		-- Teleporting player
		teleportService:Teleport(targetPlace, player)
	end
end)
1 Like

As far as I know :Teleport takes a while to run and cannot be made faster.

This. If you want it to be faster, teleport someone physically rather than to a different place.

also they could hit it multiple times and cause teleport to be called like 10 or more times

I’ll take a break from developing and just chill out. I will get a solution if there is one of course.

What you have is probably as optimized as you can make it.

But I would agree that a debounce or some tagging system to keep the event from firing multiple times for one player would be a good idea.

You could possibly add a debounce, this may help it not stack up and maybe teleport quicker.

It has nothing to do with your code.

Players do not teleport instantaneously because after Teleport is called, the teleport has to be initialised. The initialisation state includes setting up the teleport according to the arguments passed in the method as well as any internal teleport processes. Initialisations can fail or succeed, the latter which then performs the actual teleport.

There is no way to make a player teleport instantly after calling the Teleport method. You’ve already done your part so the engine takes care of the rest.

2 Likes

As said above there is little you can do to speed up the teleport process, but you can disguise it.

Try creating a custom teleport GUI, you can animate it onto the screen as the player touches the part so the player gets immediate teleport feedback. Then in the secondary place, have a local script in replicated first to react to custom teleport UIs. Just coordinate the teleport code with a local script that sets the teleport UI and animates it on screen with a remote event or similar.

For more info:

3 Likes