Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why does the teleporter not wait a few seconds before teleporting me again?

script.Parent.Touched:Connect (function(part) local humanoid = part.Parent:FindFirstChild("Humanoid") part.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace["TelePart"].Position) wait(3) end)

code here whenever i step on my teleporter it keeps teleporting me non stop against my will any fixes?

2 comments

0

Have you tried disabling the script for a certain period of time? It looks like it's running each time a part touches the scripts parent, which means any time a single part from the player touches the brick, the script runs regardless of previous limitations.

0

is there a script that disables the whole script for a period of time if the player activates it? i tried deactivating it by putting a wait which didn't work

2 answers

✓ Accepted answer

Hello! I come with a solution! The code below is simple and easy to modify for your game and I will instruct you how to do so. Let me know if you need any help! All you need to do is create a script anywhere in the workspace and put the code in there. Then change lines 1 and 2 to be the parts you want the player to teleport to and from.

local pad1 = workspace:WaitForChild("TelePart1") --Change "TelePart1" to the name of the part the player touches to teleport to the other part
local pad2 = workspace:WaitForChild("TelePart2") --Change "TelePart2" to the name of the part the player gets teleported to

local cooldownTime = 5 --This is the number of seconds before the player can teleport again
local teleportHeight = 50 --Change this to how many studs above the teleport pad you want the player to teleport to

--The code below does not need to be modified

local teleportPads = {pad1,pad2} --Table with both teleport pads
local cooldown = false --Bool that stops player from quickly teleporting back and forth

for i, pad in ipairs(teleportPads) do
	pad.Touched:Connect(function(part) --If player touches either teleport pad
		if part.Parent:FindFirstChild("Humanoid") and cooldown == false then --If the touching part is a player and the cooldown is over
			local humanoid = part.Parent:FindFirstChild("Humanoid")
			cooldown = true
			if pad == pad1 then
				part.Parent.HumanoidRootPart.CFrame = CFrame.new(pad2.Position.X,pad2.Position.Y+teleportHeight,pad2.Position.Z) 
			else
				part.Parent.HumanoidRootPart.CFrame = CFrame.new(pad1.Position.X,pad1.Position.Y+teleportHeight,pad1.Position.Z) 
			end
			wait(cooldownTime) --The wait time before the player can teleport
			cooldown = false
		end
	end)
end

5 comments

0

this script works but how do i make it so it teleports the player higher above the ground?

0

I went ahead and updated the code above and added "teleportHeight" which you can change to make the player teleport higher. All you needed to do was change the CFrame Y-axis for the teleporting position.

0

where do i add the teleportHeight thing?

0

ok nvm i used your updated script and it does better now i needed this for a game i want to make so thank you :)

0

No problem :) Glad I could help! Good luck with your game!

The problem with your script was the fact that there was no way to prevent the script from firing again once it touched another part; the wait() at the end of the script just makes the script wait before ending it, so multiple limbs could come into contact with the buttons and cause the script to fire multiple times, which results in an endless loop of teleportation.

To prevent this, add "script.disabled = true" to the script like this:

script.Parent.Touched:Connect(function(part) 
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	local button1 = script.Parent
	local button2 = workspace["TelePart"] --  change this to the name of the brick you're teleporting the player to
	if humanoid then -- if a humanoid is found then
		part.Parent.HumanoidRootPart.CFrame = CFrame.new(button1.Position) -- teleport the player
		button2.Script.Disabled = true
		script.Disabled = true
		wait(3) -- determines how long the teleport is disabled for
		button2.Script.Disabled = false
		script.Disabled = false
	end
end)

This also disables any extra teleport scripts (such as one located in the part you're teleporting the players to) to prevent the script from teleporting the player back to the original part. If you don't have any extra scripts, remove these lines

button2.Script.Disabled = true

and

button2.Script.Disabled = false

2 comments

0

your script just locks me in place

0

it says script is not a valid member of workspace.Teledestination

This discussion is preserved as it was. New answers, comments, and votes are closed.