How would I create a button, that when clicked it kills everyone in a certain area?
Your going to need some sort of client to server communication but make sure you have some sort of protection otherwise exploiters can fire it whenever they want. To fix this in my example I added a check if it is a certain user though use any system you like.
Setup
Client
--Define Remote stuff, etc
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KillRemote = ReplicatedStorage:WaitForChild("KillRemote")
--Define UI variables
local UI = script.Parent
local KillButton = UI.KillButton
--Click button
KillButton.MouseButton1Click:Connect(function()
KillRemote:FireServer() --Fire server
end)
Server
--Define Remote stuff, etc
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KillRemote = ReplicatedStorage:WaitForChild("KillRemote")
--I'm going to be using region3 for this example
--Region3 is depricated but I haven't used the replacements yet so...
local KillRegion = game.Workspace.KillRegion
local Region = Region3.new(KillRegion.Position - (KillRegion.Size/2), KillRegion.Position + (KillRegion.Size/2))
--You can find documentaion on region3 yourself. I won't be explaining it
--Recive client request to kill
KillRemote.OnServerEvent:Connect(function(Player) --Recive player who fired
if Player.Name == "DxubleG" then --If the player who fired is: then continue
local PartsInRegion = game.Workspace:FindPartsInRegion3(Region, nil, 1000)
--Last argument is how many parts you wanna check you can use math.huge if you like.
for i, v in pairs(PartsInRegion) do
if v.Parent:FindFirstChild("Humanoid") then --If parent of part has a humanoid (is a player) then...
v.Parent.Humanoid.Health = 0
end
end
end
end)