Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get all players in the server to do something?

I want to know how to gather every player in a server except for the local player and make those gathered players do something.

For example, say I want to fire a remote that sends everyone except the local player to a room.

The local player has a button that fires this remote event that sends everyone besides the local player to that specified room.

I heard about using 'game.Players:GetPlayers()' but I do not know where to go after that.

2 answers

✓ Accepted answer

You can use :GetPlayers() in a for loop to get all of the players. After that you can check if the players name doesn't equal the LocalPlayers name.

Edit: My bad I didn't read your post correctly, now that I saw it I have two scripts for you. The localscript that fires the remote once the button is clicked and the noemal script that handles the remote.

LocalScript:

local RS = game:GetService("ReplicatedStorage")
local RemoteName = "RemoteEvent"

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage:WaitForChild(RemoteName):FireServer()
end)

Normal Script:

local RS = game:GetService("ReplicatedStorage")
local RemoteName = "RemoteEvent"

game.ReplicatedStorage:WaitForChild(RemoteName).OnServerEvent:Connect(function(player)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Name ~= player.Name then
			-- your code
		end
	end
end)

3 comments

0

Oh, I assumed he wanted it in a Script, and not a LocalScript.

0

@firestarroblox123 Oh.

0

I like this solution more then my solution tbh.

This will work in a script.

local chosenPlayerName = ""--Person who will not be affected by this

for i,player in pairs(game.Players:GetPlayers()) do
	if player.Name ~= chosenPlayerName then
		--Do whatever you want with the other players
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.