Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

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)
Ad
Log in to vote
0
Answered by
RFL890 4
4 years ago
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
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" RFL890 4 — 4y

Answer this question