Can't teleport to other game place

I’m trying to make player teleport to other place through double clicking button in PC OS simulation, but it does not work. I tried to look at server script, but it seems there’s no errors.

ServerScript:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

local PLACE_ID = 88516016933703

ReplicatedStorage:WaitForChild("TeleportToHell").OnServerEvent:Connect(function(player)
	local success, err = pcall(function()
		TeleportService:Teleport(PLACE_ID, player)
	end)
end)

Local Script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local sound = script.Parent:FindFirstChild("EnterSound")
if sound and sound:IsA("Sound") then
	sound:Play()
end

-- UI Button Hover Effect
local function setButtonHoverEffect(button)
	local originalTransparency = button.BackgroundTransparency
	local originalColor = button.BackgroundColor3

	button.MouseEnter:Connect(function()
		button.BackgroundTransparency = 0.5
		button.BackgroundColor3 = Color3.fromRGB(0, 0, 255)
	end)

	button.MouseLeave:Connect(function()
		button.BackgroundTransparency = originalTransparency
		button.BackgroundColor3 = originalColor
	end)
end

-- Double-click detection and folder copy logic
local DOUBLE_CLICK_TIME = 0.3 -- seconds

-- Helper to generate a unique name for each clone (optional)
local function getUniqueCloneName(baseName, guiRoot)
	local count = 1
	local newName = baseName .. "_Copy" .. tostring(count)
	while guiRoot:FindFirstChild(newName) do
		count = count + 1
		newName = baseName .. "_Copy" .. tostring(count)
	end
	return newName
end

-- Recursively search for a frame named folderName under parent
local function recursiveFindFrame(parent, folderName)
	for _, child in parent:GetChildren() do
		if child:IsA("Frame") and child.Name == folderName then
			return child
		end
		local found = recursiveFindFrame(child, folderName)
		if found then
			return found
		end
	end
	return nil
end

-- Reference to the RemoteEvent for teleporting
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local teleportEvent = ReplicatedStorage:FindFirstChild("TeleportToHell")

local function setupFileIconDoubleClick(button, guiRoot)
	local lastClick = 0

	button.MouseButton1Click:Connect(function()
		local now = tick()
		if now - lastClick < DOUBLE_CLICK_TIME then
			-- Double-click detected
			local folderName = button.Name .. "Folder"
			local folderTemplate = nil

			-- 1. Look for folder inside the button
			folderTemplate = button:FindFirstChild(folderName)
			-- 2. If not found, look for folder as a sibling (child of guiRoot)
			if not folderTemplate then
				folderTemplate = guiRoot:FindFirstChild(folderName)
			end
			-- 3. If still not found, search recursively under guiRoot (Desktop)
			if not folderTemplate then
				folderTemplate = recursiveFindFrame(guiRoot, folderName)
			end

			if folderTemplate and folderTemplate:IsA("Frame") then
				local clone = folderTemplate:Clone()
				clone.Visible = true
				clone.Name = getUniqueCloneName(folderTemplate.Name, guiRoot)
				clone.Parent = guiRoot
			end

			-- Teleport logic for HellButton
			if button.Name == "HellButton" and teleportEvent then
				teleportEvent:FireServer()
			end
		end
		lastClick = now
	end)
end

local function applyHoverAndDoubleClickToAllButtons(parent, guiRoot)
	for _, child in parent:GetChildren() do
		if child:IsA("TextButton") or child:IsA("ImageButton") then
			setButtonHoverEffect(child)
			setupFileIconDoubleClick(child, guiRoot)
		end
		applyHoverAndDoubleClickToAllButtons(child, guiRoot)
	end
end

applyHoverAndDoubleClickToAllButtons(script.Parent, script.Parent)

RemoteEvent is in ReplicatedStorage how it should be.

1 Like

You don’t need this if it’s in ReplicatedStorage

Also, why are you teleporting players on the server when they can supposedly also teleport on the client?

Are you sure? That looks like a REALLY big number.

Edit: nevermind, the platform has changed a lot

1 Like

Just as a note, you can’t teleport in Studio, you can only teleport in-game!!

2 Likes

True, but I don’t think that’s the issue here, it gives a pretty clear error when you try that.

Whats the error say? Or does it cite a specific line of your code?

1 Like

raiseTeleportInitFailedEvent: Teleport failed because Cannot Teleport in the Roblox Studio. (Failure) - Studio
Cannot Teleport in the Roblox Studio.

This is a code from one of my projects if you try to teleport in Studio

2 Likes

i think the problem is that button couldn’t be detected inside of frames of other frames in GUI. When i made script separately it worked well. I need only to find out why it didn’t worked in first script. At first script i couldn’t even see Teleport failed message

ooooh i thought teleport client isn’t supposed to be used in client. My bad

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.