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

How do sub-places in a game connect?

Asked by 8 years ago

I'm trying to make teleporters in my active start place to teleport to an inactive place in the same game. I don't fully understand the sub-places of a game, but I'm assuming that they are the "Other Places" in a game. I've tried the sample code from the Wiki, but it doesn't seem to be working. I don't have a lot of experience with teleporting between places.

This is code inside of a touch button:

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(224906765, player) -- 224906765 is place id
    end
end
script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by 8 years ago
script.Parent.Touched:connect(function(p)
    local player =
        touched.FindFirstChild("Humanoid").Parent
    if player then
        game:GetService("TeleportService"):Teleport(224906765, player)
    end
end

I think your mistake was that you didn't properly define player. I've done my best to help, but I don't quite know how to explain.

Just a heads up, you can shorten scripts like So say if you had.

function onClick()
    --Code here
end
script.Parent.MouseClick:connect(onClick)

You could change it to

script.Parent.MouseClick:connect(function()
    --Code here
end)

So, you'd have the connect, but change the function (onClick in our case) to function(

0
My original script freezes my game in the middle of the teleportation. But I tried defining the teleporting player like you said, and nothing much happened. Looks like I learned something new today about shortening scripts, at least. Thanks hipenguinflip 30 — 8y
0
Your welcome, and sorry I can't be of any help... TheHospitalDev 1134 — 8y
Ad

Answer this question