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

How can I make this script only kill others, and not the one clicking the button?

unction onClick()
for i_, players in pairs(game.Players:GetChildren()) do --gets list of characters
	if players.Character ~= nil then --makes sure chracter/s is existent
		players.Character:BreakJoints() --kills character
	end
	
	end
end
	
script.Parent.MouseButton1Click:connect(onClick)

2 answers

✓ Accepted answer

You need to use the if statement on line 3 to determine whether or not *'players'*s Name is equivalent to the one clicking the button.

But this isn't going to work just on the client due to FilteringEnabled. You have to setup a RemoteEvent in ReplicatedStorage to tell the server to execute the code.

Use FireServer from a LocalScript and use the OnServerEvent event from the server to recieve the FireServer cal.

Script in ServerScriptStorage:

local re = game.ReplicatedStorage.ClickedButton --This is your remote

function onClick(c)
	for _, players in pairs(game.Players:Players()) do
		if players.Name ~= c.Name then
			players.Character:BreakJoints()
		end
	end
end

re.OnServerEvent:Connect(onClick)

LocalScript:

local re = game.ReplicatedStorage.ClickedButton --This is your remote

function onClick()
	re:FireServer()
end

script.Parent.MouseButton1Down:Connect(onClick)
function killOthers()
    for _, v in pairs(game.Players:GetChildren()) do
         local name = game.Players.LocalPlayer.Name
         if not v.Character.Name == name then
             v.Character.Head:Destroy()
        end
    end
end

1 comment

0

if you want to do this with an executor(do not endorse exploiting) then replace v.char.name == name with v.char.name == "YourName"

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