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)
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