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

Why can't I teleport people using TeleportService?

Will this work? If not what should I do?

local v = script.Parent.Parent
local PlaceID = v.Portal.ID.Value

function onTouched(hit)
    character = hit.Parent
        if character then
            game:GetService("TeleportService"):Teleport(PlaceID, character)
        end
end
 
script.Parent.Touched:connect(onTouched)

Here is my other script but if you can fix it then that would be great.

TeleDebounce1 = false

local LPlayer = game.Players.LocalPlayer
local BitsFrame = LPlayer.PlayerGui["_gui"]
local character = LPlayer.Character



for i,v in pairs(workspace.Portals:GetChildren()) do
v.Portal.Touched:connect(function(Who)
if Who.Parent:findFirstChild("Humanoid") and not TeleDebounce2 then
TeleDebounce2 = true
BitsFrame.Parent.TeleGui.Visible = true
--Begin Functions

local title = v.Portal.Title
local img = v.Portal.Img
local a = BitsFrame.Parent.TeleGui
a:TweenPosition(UDim2.new(0.5, -150, 0.5, -200), "Out", "Quad", 0.5)
a.Title.Text = title.Value
a.Img.Image = img.Value
BitsFrame.Parent.menuMusic:Pause()
BitsFrame.Parent.teleGui:Play()
wait(0.5)
BitsFrame.Parent.menuMusic:Play()
a:TweenPosition(UDim2.new(0, -300, 0.5, -200), "Out", "Quad", 0.5)
game:GetService("TeleportService"):Teleport(v.Portal.ID.Value, character)
--Close Gui
wait(0.5)
BitsFrame.Parent.TeleGui.Visible = false
TeleDebounce2 = false
end
end)
end

4 comments

1

Why have this as a local script, instead of a normal script? In any case that you need it to be local, use the Touched event on the local player's torso, then check if that is a portal.

0

Well I want this to be inside my framework so I don't have an overload of portals with the exact same script.

0

So make a variable called Torso? local Torso = charactar.Torso

1

Then just loop through each portal and have one script. But if you need it to be local then instead of looping through all the portals and adding an event to them, don't. Just add the connection to the Torso.

1 answer

✓ Accepted answer

You can't call TeleportService on a character. Use it on a player: (v.Portal.ID.Value, LPlayer)

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