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

why is my wiki-copied teleport script not working?

Asked by 9 years ago

I'm making a place that's like the future of Roblox and I want to make a futuristic teleport. But it won't teleport. Here's my code: Remember, I copied it from the Wiki.

ame:GetService("TeleportService").CustomizedTeleportUI = true
local teleportService = game:GetService("TeleportService")
local otherPlaceId = 101923636 -- this is the place ID i want them to teleport to.
local button = script.Parent
local loadingScreen = script.Parent.Parent
 button.MouseButton1Click:connect(function()

    game:GetService("TeleportService"):Teleport(otherPlaceId)


    loadingScreen.Visible = true


    for i = 1, 0, -.05 do
        loadingScreen.BackgroundTransparency = i
        wait()
    end
    loadingScreen.BackgroundTransparency = 0
end)

game.ReplicatedStorage.TeleportRequestEvent.OnServerEvent:connect(function(player)

    local character = player.Character
    local forceField = Instance.new("ForceField", character)


    player.OnTeleport:connect(function(teleportState)
        if teleportState == Enum.TeleportState.Failed then -- teleport to game not working
            game.ReplicatedStorage.TeleportRequestEvent:FireClient(player)
            forceField:Destroy()
        end
    end)
    teleportService:Teleport(otherPlaceId, player) -- do I need this? I copied it from Wiki.
end)

I copied this from the Wiki so it may need some changes. Thanks for reading!

1 answer

Log in to vote
1
Answered by 9 years ago

I believe that you don't need some of that code. You do need to define the player when teleport. Also I suggest that you don't just copy scripts. You should look at them and try to understand what it's doing. The code is below.

The script should be in Local Script to work!

game:GetService("TeleportService").CustomizedTeleportUI = true
local teleportService = game:GetService("TeleportService")
local otherPlaceId = 101923636
local button = script.Parent
local loadingScreen = script.Parent.Parent
local player = game.Players.LocalPlayer

 button.MouseButton1Down:connect(function()
    game:GetService("TeleportService"):Teleport(otherPlaceId, player)
    loadingScreen.Visible = true
    for i = 1, 0, -.05 do
        loadingScreen.BackgroundTransparency = i
        wait()
    end
    loadingScreen.BackgroundTransparency = 0
end)

http://wiki.roblox.com/index.php?title=Teleportation

Don't forget to accept this as an answer! I made sure that the script works.

0
thanks so much! I'm a begginer scripter and I really don't know much about teleportation and big stuff. but thanks! TroytheDestroyer 75 — 9y
Ad

Answer this question