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

How can I kill all players besides the player that pressed the button?

So the point here is, that if times goes to 5, all players should die, besides the player that pressed the Button. I really don't have any idea how to make it, so i thought to come here and ask for help, Thnx!

local simonCommands = workspace.simonCommands
local theGUIs = game.Players.LocalPlayer.PlayerGui.simonCommandsOpen.CommandsGUI.simonSays
local dontmoveRemote = game.ReplicatedStorage.simonSays.DontMove



-- SIMON SAYS JUMP
theGUIs.Jump.MouseButton1Click:Connect(function()
	simonCommands.Value = "Simon Says Jump"
	print("Simon Says Jump")

	for i, v in pairs(game.Players:GetPlayers()) do
	local JumpedAlready = Instance.new("BoolValue")
	JumpedAlready.Name = "JumpedAlready"
	JumpedAlready.Value = false
	JumpedAlready.Parent = v

	for i = 0, 4 do
		i = i + 1
		print(i)
		wait(1)

	if i == 5 and v.JumpedAlready.Value == false then
			v.Character.Humanoid.Health = 0
			print("Killing: "..v.Name)
		end
	end
end
end)

2 answers

local plr = game.Players.Player1

for i, v in pairs(game.Players:GetPlayers()) do
	if v ~= plr then
		-- do whatever
	end
end

Have a variable to reference the player that clicked the button. Iterate through all the players in the game, and for each player the loops goes to, make sure that the player isn't the player that clicked the button. If they aren't kill them. Otherwise, do nothing.

2 comments

0

How will I know who pressed the button?

0

Looking at your code, it looks like this is being done in a GUI, so you'd have to use my snippet of code on a server script, after firing a remote event from the client that is currently simon.

Try giving the player who pressed the button a BoolValue which says whether or not they clicked the button. The player you're trying to reference is game.Players.LocalPlayer.

local simonCommands = workspace.simonCommands
local theGUIs = game.Players.LocalPlayer.PlayerGui.simonCommandsOpen.CommandsGUI.simonSays
local dontmoveRemote = game.ReplicatedStorage.simonSays.DontMove



-- SIMON SAYS JUMP
theGUIs.Jump.MouseButton1Click:Connect(function()
	local simon = Instance.new("BoolValue")
	simon.Name = "Simon"
	simon.Parent = game.Players.LocalPlayer

	simonCommands.Value = "Simon Says Jump"
	print("Simon Says Jump")

	for i, v in pairs(game.Players:GetPlayers()) do
		if not v:FindFirstChild("Simon") then -- checks to see if the player is not Simon/whoever clicked the button
			local JumpedAlready = Instance.new("BoolValue")
			JumpedAlready.Name = "JumpedAlready"
			JumpedAlready.Value = false
			JumpedAlready.Parent = v

			for i = 0, 4 do
				i = i + 1
				print(i)
				wait(1)

				if i == 5 and v.JumpedAlready.Value == false then
					v.Character.Humanoid.Health = 0
            				print("Killing: "..v.Name)
        			end
    			end
		else
			print("Player is Simon")
		end
	end
end)

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