Teleporter not working

Hello devs

today I was trying to make a nice teleporter script for one of my mates games but I noticed its not working and I think its something to do with the server.

CLIENT SCRIPT

local TeleportSound: Sound = game.ReplicatedStorage.Teleporter

local RS = game:GetService("ReplicatedStorage")

local player: Player = game.Players.LocalPlayer
local UI: PlayerGui = player.PlayerGui

local transitionUI: ScreenGui = UI:WaitForChild("TransitionUI")

local remote = game.ReplicatedStorage.TeleportClient

function Transition(onOrOff: boolean)
	local frame = transitionUI.Main

	local function animate(start: number, ending: number, iD: number)
		for i = start, ending, iD do
			frame.Transparency = I
			task.wait()
		end

		frame.Transparency = ending
	end

	if onOrOff then
		animate(1, 0, -0.05)
	else
		animate(0, 1, 0.05)
	end
end

remote.OnClientEvent:Connect(function(location: BasePart)
	TeleportSound:Play()
	Transition(true)
	wait(1.5)
	Transition(false)
	local remote = game.ReplicatedStorage.Teleport
	remote:FireServer(location)
end)

SERVER SCRIPT

local remote = game.ReplicatedStorage.Teleport

remote.OnServerEvent:Connect(function(player: Player, location: BasePart)
	if location and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		player.Character.HumanoidRootPart.CFrame = location.CFrame
	end
end)

Can anyone help me with this?

1 Like

you’re supposed to use fireserver on the local script and on the server script it’s onserverevent. I don’t think you fireserver the remote event, also why not handle teleporting on the local script, the player has networkownership over their character so if a hacker wanted to teleport he could anyways?

1 Like

it gave me an error when I done this.

ServerScriptService.TeleportServer:4: attempt to index nil with 'CFrame'

that means you tried to use cframe on nothing, can you print location?

this is the script I tried using.

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player: Player = Players.LocalPlayer
local UI: PlayerGui = player:WaitForChild("PlayerGui")
local transitionUI: ScreenGui = UI:WaitForChild("TransitionUI")

local TeleportSound: Sound = RS:WaitForChild("Sounds"):WaitForChild("Teleporter")
local remote: RemoteEvent = RS:WaitForChild("Teleport")

local function Transition(onOrOff: boolean)
	local frame = transitionUI:WaitForChild("Main")

	local function animate(start: number, ending: number, step: number)
		for i = start, ending, step do
			frame.Transparency = I
			task.wait()
		end
		frame.Transparency = ending
	end

	if onOrOff then
		animate(1, 0, -0.05) -- Fade in
	else
		animate(0, 1, 0.05)  -- Fade out
	end
end

local function TeleportPlayer(player: Player, place: BasePart)
	Transition(true)
	task.wait(1.5)

	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		player.Character.HumanoidRootPart.CFrame = place.CFrame
	end

	TeleportSound:Play()
	Transition(false)
end

remote.OnClientEvent:Connect(function(place: BasePart)
	TeleportPlayer(player, place)
end)

well you didn’t fire to the server, on the localscript you’re supposed to do remote:FireServer(), onclientevent only works if you use fireclient or fireclients on the serverscript.

remotes work like this

local script

local player = game.Players.LocalPlayer
local remote = game.ReplicatedStorage.RemoteEvent

remote:FireServer()

server script

local remote = game.ReplicatedStorage.RemoteEvent


remote.OnServerEvent:Connect(function(player)
	print(player)
end)

I know this so do you see any problems with this? ( I can’t see the problem I can paste the script that teleports the player when they touch the part if you want )

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player: Player = Players.LocalPlayer
local UI: PlayerGui = player:WaitForChild("PlayerGui")
local transitionUI: ScreenGui = UI:WaitForChild("TransitionUI")

local TeleportSound: Sound = RS:FindFirstChild("Teleporter")
local remote: RemoteEvent = RS:WaitForChild("Teleport")

local function Transition(onOrOff: boolean)
	local frame = transitionUI:WaitForChild("Main")

	local function animate(start: number, ending: number, step: number)
		for i = start, ending, step do
			frame.Transparency = I
			task.wait()
		end
		frame.Transparency = ending
	end

	if onOrOff then
		animate(1, 0, -0.05) -- Fade in
	else
		animate(0, 1, 0.05)  -- Fade out
	end
end

local function TeleportPlayer(player: Player, place: BasePart)
	Transition(true)
	task.wait(1.5)

	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		player.Character.HumanoidRootPart.CFrame = place.CFrame
	end

	TeleportSound:Play()
	Transition(false)
end

remote.OnClientEvent:Connect(function(place: BasePart)
	TeleportPlayer(player, place)
end)

yes this part, unless you in the serverscript do remote:FireClient() you shouldn’t be using onclientevent

I am using fire client on a server script inside the part

well you should be handling teleporting on a local script instead of the server. Also you can’t get the local player on the server script because the server script is usually for the game itself and localscripts for each player. Also you need to do remote FireServer which can only be done in a local script

ok ima try that thank you and if its right ill Solution it

I tried switching to a click detector and it does still not work but I dont even get an error…

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local UI = player:WaitForChild("PlayerGui")
local transitionUI = UI:WaitForChild("TransitionUI")

local TeleportSound = RS:FindFirstChild("Teleporter")
if TeleportSound then
	TeleportSound = TeleportSound:Clone()
	TeleportSound.Parent = UI
end

local function Transition(onOrOff: boolean)
	local frame = transitionUI:WaitForChild("Main")

	local function animate(start: number, ending: number, step: number)
		for i = start, ending, step do
			frame.BackgroundTransparency = I
			task.wait()
		end
		frame.BackgroundTransparency = ending
	end

	if onOrOff then
		animate(1, 0, -0.05) -- Fade in
	else
		animate(0, 1, 0.05)  -- Fade out
	end
end

local function TeleportPlayer(place: BasePart)
	Transition(true)
	task.wait(1.5)
	
	local character = player.Character
	
	character.HumanoidRootPart.CFrame = place.CFrame

	Transition(false)
end

local TeleportPartsFolder = workspace:WaitForChild("TeleportParts")
local TeleportPart1 = TeleportPartsFolder:WaitForChild("TeleportPart1")
local TeleportPart2 = TeleportPartsFolder:WaitForChild("TeleportPart2")

TeleportPart1:WaitForChild("ClickDetector").MouseClick:Connect(function()
	TeleportPlayer(TeleportPart2)
end)

TeleportPart2:WaitForChild("ClickDetector").MouseClick:Connect(function()
	TeleportPlayer(TeleportPart1)
end)

well, functions work like this

local part = workspace.Part

function touched(hit)
   print(hit)

end

part.Touched:Connect(touched)

-- or you can connect a function directly instead

part.Touched:Connect(function(hit)
   print(hit)
end

what you’re doing is connecting a function directly then redirecting it to another function. Also MouseClick only works for click detectors are you sure teleportpart1 is the click detector and not the part? Also you have a function inside a function. You should just have the teleportplayer function do most of this instead of making it into separate functions

Wait I fixed the problem the teleport part was too far away for roblox to render it and streamEnabled was true so it did not work