Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't I teleport people using TeleportService?

Asked by 10 years ago

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

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. User#2 0 — 10y
0
Well I want this to be inside my framework so I don't have an overload of portals with the exact same script. IntellectualBeing 430 — 10y
0
So make a variable called Torso? local Torso = charactar.Torso IntellectualBeing 430 — 10y
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. User#2 0 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

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

Ad

Answer this question