I wanted to make a teleporter using only one part which is a block that can teleport players to another teleporter also made using one part that is a block placed any where in the world.
I tried a lot but i couldn’t achieve it.I also tried using roblox Dev’s shared library for pre built models but it still didn’t work.
If it’s a teleporter in the same game, like a portal or something, try this -
local Part1 = script.Parent -- your teleporter
local Destination = "YourDestination" -- the part where you want them to be teleported
Part1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Real_Player = game.Players:GetPlayerFromCharacter(hit.Parent)
--checking if it's a valid player, and not a NPC
if not Real_Player then return end
hit.Parent:PivotTo(Destination.CFrame)
end
end)
this will make the character teleport from part1 to part2 but not from part2 to part1
local part1 = workspace.Part1
local part2 = workspace.Part2
-- when something touches the part call this function
part1.Touched:Connect(function(touchedPart)
-- assume the touch part parent is the character model
local character = touchedPart.Parent
-- try to get the player from the character variable
local player = game.Players:GetPlayerFromCharacter(character)
-- if player = nil that means the character variable was not a character model
if player == nil then return end
-- teleport the character to part2
character:PivotTo(part2.CFrame)
end)
local PartA = workspace:WaitForChild("PartA") -- Define our Location PartA and wait for it to spawn
local PartB = workspace:WaitForChild("PartB") -- Define our Location PartB and wait for it to spawn
local PartC = workspace:WaitForChild("PartC") -- Define our Location PartC and wait for it to spawn
local PartD = workspace:WaitForChild("PartD") -- Define our Location PartD and wait for it to spawn
local Teleporters = { -- Dictionary with our teleport paths
["TeleportA"] = {["LocationA"]=PartA, ["LocationB"]=PartB}; -- Our first teleportation, between two parts
["TeleportB"] = {["LocationA"]=PartC, ["LocationB"]=PartD}; -- Our second teleportation, between two parts
}
local GlobalTeleportDebounce = {} -- This is used to store our player's character in a global teleport debounce, so when they get teleported to the new location, they won't get teleported back right away
local GlobalDebounceCooldown = 5 -- seconds -- they have 5 seconds to move away from the teleport part, before getting teleported back.
local LocalDebounceCooldown = 2 -- seconds -- they can only activate a teleport part every 2 seconds, this makes sure that they won't trigger the teleporter more than once, before their character have been teleported
local function SetupTeleporter(FromPart,ToPart) -- A function to setup a teleport path between two parts, a "FromLocation"-Part, to a "ToLocation"-Part
local TeleportDebounce = {} -- Make a empty table for our teleportpath. This is used to put the player's character's name into the table, when they activate the teleporter, to make the "LocalDebounceCooldown" work.
FromPart.Touched:Connect(function(Hit) -- When our teleportPart gets touched by something
local Character = Hit.Parent -- We temporarily define that the hit.Parent is a character.
local Humanoid = Character:FindFirstChildWhichIsA"(Humanoid") -- If we find a Humanoid in Character (or Hit.Parent), then we know for sure that it is really a character!
if Humanoid and Humanoid.Health > 0 then -- Here we check if the Humanoid is present, and if it is, check if it's alive.
if not TeleportDebounce[Character.Name] then -- If we can't find the character name in our local TeleportDebounce, then it indicates that they have not activated this teleporter recently
if not GlobalTeleportDebounce[Character.Name] or tick() - GlobalTeleportDebounce[Character.Name] > GlobalDebounceCooldown then -- If they're not a part of our GlobalTeleportDebounce table, or if time passed, since they last time activated a teleporter is more than "GlobalDebounceCooldown", then pass them through
TeleportDebounce[Character.Name] = true -- Put them into our local teleporters table, so they won't fire the teleporter more than once, before teleporting is complete
GlobalTeleportDebounce[Character.Name] = tick() -- Put them into the GlobalTeleportDebounce and set the time to the current tick() - (Tick is the amount of seconds passed since a set date.. many years ago)
Character:PivotTo(ToPart:GetPivot()+Vector3.new(0,5,0) -- Teleport their character to the ToPart location
task.wait(LocalDebounceCooldown) -- Wait the amount of seconds that LocalDebounceCooldown is set at
TeleportDebounce[Character.Name] = nil -- Remove them from the local TeleportDebounce table, so they again can activate this very teleportPart.
end
end
end
end)
end
for TeleportName, TeleportData in pairs(Teleporters) do -- Loop through all our TeleportParts
if TeleportData["LocationA"] and TeleportData["LocationB"] then -- If we have both LocationA and LocationB in our data for the specific teleportPath then..
SetupTeleporter(TeleportData["LocationA"],TeleportData["LocationB"]) -- Make so LocationA goes to LocationB when touched.
SetupTeleporter(TeleportData["LocationB"],TeleportData["LocationA"]) -- Make so LocationB goes to LocationA when touched.
end
end
Haven’t tested it, but the whole idea is, you can easily add new teleportations between two teleport parts, by creating new values in the Teleporters dictionary. I’ve made 2 so far.
Please let me know if you’re confused about any of it. Better ask for advice, than just taking the script, and hope it works.
I can add more parts like 5 parts? Im trying make game there safe zone and pvp zone. in safe zone there teleporter part it can teleport Player to pvp zone