Okay, let's create the basic room setup with teleporting functionality. I'll provide the room structure, button setup, and scripts for this.
Step 1: Create Room 1 and Room 2
Create Room 1:
In Roblox Studio, create a small room.
Place a part named Button1 inside Room 1.
Position Button1 somewhere accessible.
Add a part named TeleportPart2 in Room 2.
Position TeleportPart2 where the player should appear when teleporting to Room 2.
Create Room 2:
Build a separate room near Room 1.
Place a part named Button2 inside Room 2.
Position Button2 somewhere accessible.
Add a part named TeleportPart3 in Room 3.
Position TeleportPart3 where the player should appear when teleporting to Room 3.
Create Room 3
Build a separate room near Room 2.
Step 2: Add Scripts to Room 1 Button
Insert a Script:
Inside Button1, add a Script.
Rename the Script to ButtonScript.
Copy and paste the following code into the Script:
lua
-- // Variables
local Button = script.Parent -- // The button part
local ClickDetector = Instance.new("ClickDetector") -- // Creating a click detector
local TeleportPartName = "TeleportPart2" -- // Teleport Location.
local Cooldown = 3 -- // Cool down timer.
-- // Properties
Button.Transparency = 0 -- // Set Transparency.
Button.CanCollide = false -- // Turn Collision off
-- // Child
ClickDetector.Parent = Button -- // Parent Click Detector.
-- // Local
local CanUse = true -- // Can use?
-- // Function
local function ButtonClicked(Player)
-- // Check if used already.
if CanUse then
CanUse = false
-- // Find Teleport Part Location.
local PartFound = workspace:FindFirstChild(TeleportPartName)
-- // Check if teleport part exist.
if PartFound then
-- // Check if HumanoidRootPart Exist.
if Player.Character:FindFirstChild("HumanoidRootPart") then
-- // Get character.
local Char = Player.Character
-- // Get CFrame
local CFrameFound = PartFound.CFrame
-- // Play Teleport Animation.
-- // Teleport
Char.HumanoidRootPart.CFrame = CFrameFound
-- // Teleport Success.
task.wait(Cooldown)
CanUse = true
else
print("HumanoidRootPart does not Exist.")
end
else
print("TeleportPart not found.")
end
else
print("Wait for cool down.")
end
end
-- // Connecting
ClickDetector.MouseClick:Connect(ButtonClicked)
Step 3: Add Scripts to Room 2 Button
Insert a Script:
Inside Button2, add a Script.
Rename the Script to ButtonScript.
Copy and paste the following code into the Script:
lua
-- // Variables
local Button = script.Parent -- // The button part
local ClickDetector = Instance.new("ClickDetector") -- // Creating a click detector
local TeleportPartName = "TeleportPart3" -- // Teleport Location.
local Cooldown = 3 -- // Cool down timer.
-- // Properties
Button.Transparency = 0 -- // Set Transparency.
Button.CanCollide = false -- // Turn Collision off
-- // Child
ClickDetector.Parent = Button -- // Parent Click Detector.
-- // Local
local CanUse = true -- // Can use?
-- // Function
local function ButtonClicked(Player)
-- // Check if used already.
if CanUse then
CanUse = false
-- // Find Teleport Part Location.
local PartFound = workspace:FindFirstChild(TeleportPartName)
-- // Check if teleport part exist.
if PartFound then
-- // Check if HumanoidRootPart Exist.
if Player.Character:FindFirstChild("HumanoidRootPart") then
-- // Get character.
local Char = Player.Character
-- // Get CFrame
local CFrameFound = PartFound.CFrame
-- // Play Teleport Animation.
-- // Teleport
Char.HumanoidRootPart.CFrame = CFrameFound
-- // Teleport Success.
task.wait(Cooldown)
CanUse = true
else
print("HumanoidRootPart does not Exist.")
end
else
print("TeleportPart not found.")
end
else
print("Wait for cool down.")
end
end
-- // Connecting
ClickDetector.MouseClick:Connect(ButtonClicked)
Step 4: Test the Teleport System
Test Game:
Enter the game by pressing Play.
Click on Button1 to teleport to Room 2.
Click on Button2 to teleport to Room 3.
Ensure everything is working smoothly and the player appears at the correct Teleport Part.
Troubleshooting:
TeleportPart Not Found: Ensure the TeleportPartName in the script matches the exact name of the part.
Player Getting Stuck: Make sure the CanCollide property is off for the button.
ClickDetector: Make sure the ClickDetector is parented under the button.
This setup should provide the fundamental teleport system. Let me know what the end goal is and I can provide other scripts to make the room bigger or have mechanics.