##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 = ...
requestAllTeleport:FireServer()
####Server
local requestAllTeleport = ...
local function teleportAllToPlayer()
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
}
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
4 comments
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?
Use a local script to fire the remote event and a server script to detect onserverevent (which is what actually executes the code)
specific player can teleport all players but i have that already. the gui will be copyed to there playergui
event:FireServer("HERE") so where i put HERE what should i put there then?