Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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?

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. flamethower2002 50 — 3y
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 dylancrazy88 20 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
this script works but how do i make it so it teleports the player higher above the ground? dylancrazy88 20 — 3y
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. BunnyFilms1 297 — 3y
0
where do i add the teleportHeight thing? dylancrazy88 20 — 3y
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 :) dylancrazy88 20 — 3y
0
No problem :) Glad I could help! Good luck with your game! BunnyFilms1 297 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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
0
your script just locks me in place dylancrazy88 20 — 3y
0
it says script is not a valid member of workspace.Teledestination dylancrazy88 20 — 3y

Answer this question