Teleport all players on touch of an object

I am making a game and when they touch part i want a gui to pop up on all screens for 5 sec and then tp all players to another place.

Summary

function onTouched(hit)

local TeleportService = game:GetService(“TeleportService”)

TeleportService:Teleport(6036609366)

end

script.Parent.Touched:connect(onTouched)

I am new to scripting and any help will be appreciated.

1 Like

you need playerobject to teleport so it should be :Teleport(PlaceId, PlayerToTeleport). You can get all players by using a for i,v in pairs() do loop when they touch to part.

local ts = game:GetService('TeleportService')

function onTouched(hit)
    if hit.Parent:FindFirstChildOfClass('Humanoid') then
        for i,v in pairs(game.Players:GetChildren())do
            ts:Teleport(6036609366, v)
        end
    end
end

script.Parent.Touched:Connect(onTouched)
2 Likes

should it be local or normal script?

It should be a normal script, yeah.