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 11 years ago

Will this work? If not what should I do?

01local v = script.Parent.Parent
02local PlaceID = v.Portal.ID.Value
03 
04function onTouched(hit)
05    character = hit.Parent
06        if character then
07            game:GetService("TeleportService"):Teleport(PlaceID, character)
08        end
09end
10 
11script.Parent.Touched:connect(onTouched)

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

01TeleDebounce1 = false
02 
03local LPlayer = game.Players.LocalPlayer
04local BitsFrame = LPlayer.PlayerGui["_gui"]
05local character = LPlayer.Character
06 
07 
08 
09for i,v in pairs(workspace.Portals:GetChildren()) do
10v.Portal.Touched:connect(function(Who)
11if Who.Parent:findFirstChild("Humanoid") and not TeleDebounce2 then
12TeleDebounce2 = true
13BitsFrame.Parent.TeleGui.Visible = true
14--Begin Functions
15 
View all 34 lines...
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 — 11y
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 — 11y
0
So make a variable called Torso? local Torso = charactar.Torso IntellectualBeing 430 — 11y
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 — 11y

1 answer

Log in to vote
1
Answered by 11 years ago

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

Ad

Answer this question