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)
how do I teleport all players using a remote event?
You're trying to teleport everyone on your client. That just doesn't work.
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)
local requestAllTeleport = ... --// assumed reference to remote event requestAllTeleport:FireServer()
local requestAllTeleport = ... --// assumed reference to remote event local function teleportAllToPlayer() --// logic end local function handleTeleportAllTeleportRequest(player) teleportAllToPlayer end requestAllTeleport.OnServerEvent:Connect(handleTeleportAllTeleportRequest)
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.
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.
local replicatedStorage = game:GetService("ReplicatedStorage") local teleportAllRequest = replicatedStorage:WaitForChild("TeleportAllRequest") local button = script.Parent local function buttonPressed() teleportAllRequest:FireServer() end button.MouseButton1Click:Connect(buttonPressed)
Uncopylocked place you can test with all the code, might not work rushed it. https://www.roblox.com/games/2659956906/handle-teleport-all