Hey guys, I need help making a button that teleports all players in the game.
What do I need?
I want to make a button that teleports all players in the game to the activator.
So if I clicked the button, all the players in the game would teleport to me.
and, if my friend clicked the button, all players in the game would teleport to my friend.
Did you search?
I looked on YouTube and the Roblox forums, but I couldn’t find what I was looking for.
local players = game:GetService("Players") -- players service
local button = path.Button -- set the variable to the button that has to be pressed
local player = players.LocalPlayer -- the player who clicked the button
button.MouseButton1Click:Connect(function() -- check when the button is clicked
for _, other in pairs(players:GetPlayers()) do -- :GetPlayers() is a function that returns a table with all the players in the server. we loop through it to teleport every player
if other.Name ~= player.Name then -- to prevent teleporting the player to itself
other.Character:FindFirstChild("HumanoidRootPart").CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame -- teleports the other players to the clicked player's CFrame
end
end)
end)
LocalScript? why?
That wont work, changing the position of other parts owned by other clients by a clientScript?
That script should be run by server, just fire the remote from the client GUI script to server and run the code that @PosFind sent
local button = script.Parent
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local teleportEvent = ReplicatedStorage.Events.teleportAllplayersEvent
button.MouseButton1Down:Connect(function()
teleportEvent:FireServer()
game.SoundService.menuClick:Play()
end)
Server Script:
local players = game.Players
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local teleportEvent = ReplicatedStorage.Events.teleportAllplayersEvent
teleportEvent.OnServerEvent:Connect(function(player)
for _, other in pairs(players:GetPlayers()) do
if other.Name ~= player.Name then
other.Character:FindFirstChild("HumanoidRootPart").CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame
end
end
end)
By quick reading, it should work, just test it and watch for the output.
btw, would be better to check if other ~= player then instead of checking for names, check for player instance.
You did mention you want this for you and your friend, add some if statements that compares the UserId, to only allow you and your friend to use the remote on server side
ok, and for me and my friend, I already made an admin menu that’ only the player that I specified can access the menu and inside the menu, there is the teleport button that I told you about, so I don’t need to add statements
here is the script I made for the players thaT I WANT TO ACCESS THE MENu
admins = {1750930982,2916311109,2859393685}
game.Players.PlayerAdded:Connect(function(plr)
if table.find(admins, plr.UserId) then
game.SoundService.promotion.Volume = 0.3
plr.PlayerGui:WaitForChild("AdminMenu").Enabled = true
else
game.SoundService.promotion.Volume = 0
plr.PlayerGui:WaitForChild("AdminMenu").Enabled = false
end
end)
Thats easily exploitable.
You are just enabling the visual of a ScreenGui, but seems that all players in server has the GUI just disabled.
With any decent injector I could enable that AdminMenu GUI, and fire the server remote.
The function connected to the remote in server should have sanity checks, to check if player firing the remote is an allowed UserId.
And plus, do not place the adminMenu in StarterGui, keep it in ServerStorage, and on PlayerAdded event, check UserId, clone adminMenu and give it to the players allowed, plus the sanity remote check, otherwise, if I dont even have the GUI, I still can fire the remote if theres no sanity checks on it.
Sanity check, just an if statement or anything you prefer, that checks that the player firing the remote is a member of your adminTable.
You are just doing a sanity check on playerAdded, enabling a GUI. a GUI that all players has (disabled), so any client can manually enable it, and use it, or just fire the remote without using the GUI.
So the function connected to the remote should check the UserId, not only the PlayerAdded event, and ofc not by just enabling a GUI.
local ServerStorage = game:WaitForChild("ServerStorage")
local AdminsMenu = ServerStorage:WaitForChild("AdminMenu") -- Reference, no Clone()
admins = {1750930982,2916311109,2859393685}
game.Players.PlayerAdded:Connect(function(plr)
if table.find(admins, plr.UserId) then
game.SoundService.promotion.Volume = 0.3
local adminPanel = AdminsMenu:Clone() -- Clone in here
adminPanel.Parent = plr.PlayerGui -- Give
adminPanel.Enabled = true
else
game.SoundService.promotion.Volume = 0
-- This is not needed cause StarterGui doesnt have the AdminMenu, so none players has it
-- plr.PlayerGui:WaitForChild("AdminMenu").Enabled = false
end
end)
Yup, thats better, dont forget to add the sanityCheck (check admins table again) when the remote functions in server runs, otherwise, a exploiter without the menu can just grab your remote and fire it as they want
ok thanks, but still I didn’t understand what you mean with sanity-check do I add the sanity-check thing in the other script that teleports all players?
Exactly, the functions connected to the remotes that only the admins should use
Just do a sanitycheck on all the remotes that only admins can use again, as you did with the giving AdminMenu, otherwise a exploiter could fire those remotes no matter if they have the adminMenu gui or not.
So functions connected to those remotes should be secured:
admins = {1750930982,2916311109,2859393685}
teleportEvent.OnServerEvent:Connect(function(player)
if table.find(admins, player.UserId) then
-- the "teleport stuff"
end
end)
admins = {1750930982,2916311109,2859393685}
local players = game.Players
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local teleportEvent = ReplicatedStorage.Events.teleportAllplayersEvent
teleportEvent.OnServerEvent:Connect(function(player)
if table.find(admins, player.UserId) then
for _, other in pairs(players:GetPlayers()) do
if other ~= player then
other.Character:FindFirstChild("HumanoidRootPart").CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame
end
end
end
end)
Yup, in that way your admin remotes would be secured, only the ids in the list can run the function. Exploiters can spam your remotes so sanityChecks based on ids, tables, timeStamp (last time a player used the remote) are really needed to keep game secured.
One more thing, just add a CFrame multiplier on that code, so all other players teleported wont spawn exactly in the same coordinate as the admin… Make them spawn around the admin not in the same exact spot (otherwise all players will collide with each other cause they got teleported to the exact same coordinate as the admin):
– A basic offset other.Character:FindFirstChild("HumanoidRootPart").CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(math.random(-13,13),1,math.random(-13,13))
yo btw the last thing, when I click the button It will teleport all players to me but sometimes its glitches, and players get punched away because players can collide how can I make all players go throw each other