Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is TeleportService not working with me?

    local TeleportService = game:GetService("TeleportService")
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local Players = game:GetService("Players")
     
    local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
     
    local placeId = 4455580329
    local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")
     
    -- parent the loading gui for this place
    loadingGui.Parent = playerGui
     
    -- set the loading gui for the destination place
    TeleportService:SetTeleportGui(loadingGui)
     
    -- teleport the user
    script.Parent.Touched:Connect(function()
    	TeleportService:Teleport(placeId)
    end)

Hello, this script is not working. I do not know why because its not giving me any errors. This is a local script inside of an axe mesh named "Axe". I edited a script off of https://developer.roblox.com/en-us/api-reference/function/TeleportService/Teleport and double checked it with the page information, but I'm pretty sure it should work.

Thanks for reading, Narwhal

2 answers

✓ Accepted answer

Okay this is my revised answer lol

So since you have a LocalScript in a part inside of workspace, that local script is not going to run at all. This is because LocalScripts are Client based, meaning that they're scripts that run on the player side. You need to place a Script inside of the part instead of a LocalScript because Scripts are Server based, meaning they'll work in workspace.

So replace your LocalScript with a Script, and instead enter this:

local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
 
local placeId = 0 -- replace here

script.Parent.Touched:connect(function(objectTouched)
	if objectTouched.Parent:findFirstChild("Humanoid") then -- checks if character touched
		local player = Players:GetPlayerFromCharacter(objectTouched.Parent)
		if player then
			local loadingGui = ReplicatedStorage:WaitForChild("loadingGui"):clone()
			loadingGui.Parent = player.PlayerGui
			TeleportService:SetTeleportGui(loadingGui)
			TeleportService:Teleport(placeId, player)
		end
	end
end)

I think that should work

25 comments

0

ok thanks ill check it out

0

okay let me know if you still need help

0

It still didn't work. I don't think there was any errors in the console still.

0

are you testing this on studio? because you aren't able to teleport to places on studio you have to be on the published game

0

No, i did it both on studio and the published game, and yes i did publish the game.

0

OHHHH okay i know what's wrong, is the local script inside of an axe in workspace?

0

I made it so the local script was in a part in workspace on top of the axe. So kinda, yeah.

0

you can't use local scripts in the server (workspace is the server), so you're going to have to use a script and a way to get the player from the part. I'll make another answer real quick

0

Kk. Thanks for the help, I've had problems with this issue before (the whole server and client thing) but I didn't know that the workspace was server based.

0

there i edited my answer, that should work but it looks like someone beat me to it lol

0

Doesn't work because playerGui needs to be defined.

0

there i fixed it

0

try it now

0

It didn't work .-. this has been going on for an hour now. gosh.

0

Heres an error i found. Workspace.AxePart.TeleScript:16: attempt to index upvalue 'loadingGui' (a nil value)

0

did you make a loading gui for the teleport?

0

because if not i edited it so you don't use it

0

OML ITS BECAUSE I DIDN'T PUT THE GUI IN THE REPLICATED STORAGE AND I SOME HOW DELETED IT ON ACCIDENT LMAO! that was to dramatic.

0

what did you name it?

0

OMG

0

there i edited it for the loading gui, hopefully it works this time

0

WORKS!

0

let me know lmao

0

IT WORKS YES!

0

YES!

Teleport Service requires 2 parameters. The place id, and the player that you want to be teleported.Here is your script, with some minor adjustments :)

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

local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")

local placeId = 4455580329
local loadingGui = ReplicatedStorage:FindFirstChild("LoadingGui")

-- parent the loading gui for this place
loadingGui.Parent = playerGui

-- set the loading gui for the destination place
TeleportService:SetTeleportGui(loadingGui)

-- teleport the user
script.Parent.Touched:Connect(function(hit)
	local plr = Players:GetPlayerFromCharacter(hit.Parent) --checks if touched part is a player
	if plr then
		TeleportService:Teleport(placeId, plr)
	else
		print("hit is not a player")
	end
end)

1 comment

0

Doesn't work because playerGui needs to be defined, but when its defined it uses local player.

This discussion is preserved as it was. New answers, comments, and votes are closed.