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

How do I make an exception for me in a game?

script.Parent.MouseButton1Click:Connect(function()
	plr = game.Players:GetPlayers()
	if plr.Name ~= "ArcanZus"
		then
		-- Random code
	end
end)

Imagine I wanted to kill everyone in a server with a button but not me. Is this the correct way to make an exception?

Thank you for your attention! I'm still learning so I might have made a stupid mistake.

2 comments

0

I'd use a for loop iterating through all the players.. :GetPlayers() would return a table, which you can't index a Name property at all

0

I'd suggest using a for loop after the function, ~= your name from the "Object" then kill them like that.

2 answers

✓ Accepted answer

Requote from my comment:

I'd use a for loop iterating through all the players.. :GetPlayers() would return a table, which you can't index a Name property at all

Here's a sample where you'd kill everyone except yourself.

script.Parent.MouseButton1Click:Connect(function()
    for _, player in pairs(game.Players:GetPlayers()) do
        if player.Character and player.Name ~= 'ArcanZus' then
    		player.Character.Humanoid.Health = 0
    		-- We could use :TakeDamage() if we wanted to subtract a specific amount of health, but this would not kill characters with forcefields.
    	end
    end
end)

If we wanted this to work with FilteringEnabled, we'd use a RemoteEvent to make the server receive our request, and proceed with the task

-- LocalScript
local event = game:GetService("ReplicatedStorage"):WaitForChild("KillEveryone")

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer()
end)

((Separating both markups))

-- ServerScript
local event = Instance.new("RemoteEvent")
event.Name = 'KillEveryone'
event.Parent = game:GetService("ReplicatedStorage")

event.OnServerEvent:Connect(function(plr)
	for _, player in pairs(game.Players:GetPlayers()) do
		if player.Character and player.Name ~= 'ArcanZus' then
			player.Character.Humanoid.Health = 0
			-- We could use :TakeDamage() if we wanted to subtract a specific amount of health, but this would not kill characters with forcefields.
		end
	end
end)

2 comments

1

Although you should not use this locally, you should hook up with a RemoteEvent

0

I've made right now a example of how you would make it correctly.

Hope this helps

script.Parent.MouseButton1Click:connect(function()
	if game.Players.Localplayer.Character.Name ~= "ArcanZus" then
		-- random code
	end
end)

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