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

how do i teleport all players using a remote event?

Asked by
danglt 185
5 years ago

I get half of remote event but part of it im still not sure of, one of my other questions used change text function so now I'm confused how to do this.

function click()
for i, player in ipairs(game.Players:GetChildren()) do
   --Make sure the character exists and its HumanoidRootPart exists
   if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
       --add an offset of 5 for each character
      player.Character.HumanoidRootPart.CFrame = CFrame.new(98.3, 0.95, 109.75)
   end
end
end
script.Parent.MouseButton1Click:Connect(click)
0
I'm guessing this is a local script? And a question from me, do you want a player to teleport everyone or only specific player can teleport all players? XviperIink 428 — 5y
0
Use a local script to fire the remote event and a server script to detect onserverevent (which is what actually executes the code) LoganboyInCO 150 — 5y
0
specific player can teleport all players but i have that already. the gui will be copyed to there playergui danglt 185 — 5y
0
event:FireServer("HERE") so where i put HERE what should i put there then? danglt 185 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

Question

how do I teleport all players using a remote event?

The Problem

You're trying to teleport everyone on your client. That just doesn't work.

Answer

You can use the FireServer method for remote events on the client and handle the OnServerEvent signal on the server.

(Sorry im late I was working on a project, I saw your post earlier though.) (Press accept answer is this helped tho lol!) (Sorry for rushing the answer I have to go soon) (Sorry if I made any mistakes in the code am rushing)

Example Code

Client

local requestAllTeleport = ... --// assumed reference to remote event

requestAllTeleport:FireServer()

Server

local requestAllTeleport = ... --// assumed reference to remote event

local function teleportAllToPlayer()
    --// logic
end

local function handleTeleportAllTeleportRequest(player)
    teleportAllToPlayer
end

requestAllTeleport.OnServerEvent:Connect(handleTeleportAllTeleportRequest)

Tutorial

So what we can do is create a remote event in ReplicatedStorage since we its a good place to place remote events since it is for storing stuff that needs to be replicated to every client individually. Then we can make a "Script" instance in ServerScriptService to handle our serverside code for this event. We can call this script "HandleTeleportAllRequest_Server" since it will be handling the serverside for the `TeleportAllRequest remote.

We will want to define ReplicatedStorage so we can index our remote TeleportAllRequest. We can get a service with GetService. We will also want to connect a function to the OnServerEvent signal and create a whitelist system so unauthorized players can't teleport everyone. If they are found in the whitelist then teleport everyone to them.

Server

local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")

local teleportAllRequest = replicatedStorage:WaitForChild("TeleportAllRequest")

local whitelisted = {
    ["LimitedLogic"] = true,
    ["SinisterMemories"] = true --// remove later if you want
}

local function teleportAllToPlayer(teleportTo)
    local teleportCharacter = teleportTo.Character
    local teleportRoot = teleportCharacter:WaitForChild("HumanoidRootPart")

    for i, player in next, players:GetPlayers() do
        local character = player.Character

        if character and player ~= teleportTo then
            local root = character:WaitForChild("HumanoidRootPart")

            root.CFrame = teleportRoot.CFrame
        end
    end
end

local function handleTeleportAllRequest(player)
    if whitelisted[player.Name] then
        teleportAllToPlayer(player)
    end
end

teleportAllRequest.OnServerEvent:Connect(handleTeleportAllRequest)

We will just use a gui text button and when its clicked fire the event. Get reference to the event and fire it.

Client

local replicatedStorage = game:GetService("ReplicatedStorage")

local teleportAllRequest = replicatedStorage:WaitForChild("TeleportAllRequest")
local button = script.Parent

local function buttonPressed()
    teleportAllRequest:FireServer()
end

button.MouseButton1Click:Connect(buttonPressed)

Extra

Uncopylocked place you can test with all the code, might not work rushed it. https://www.roblox.com/games/2659956906/handle-teleport-all

Ad

Answer this question