Trying to loopkill a player when button is clicked

hello! i want to loopkill a player that is selected in the menu but im not sure how to do it. i tried using a bindable event but i have no idea what im doing… ty!

script:

function updPlrs()
	local plr = game.Players.LocalPlayer
	local thumbnailtype = Enum.ThumbnailType.HeadShot
	local thumbnailsize = Enum.ThumbnailSize.Size420x420

	for i, p in pairs(game.Players:GetPlayers()) do
		if (script.Parent.plrScroll:FindFirstChild(p.Name)) then continue end
		local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)

		local templateClone = template:Clone()
		templateClone.Name = p.Name
		templateClone.Visible = true
		templateClone.Text = p.Name
		templateClone.displayName.Text = "@"..p.DisplayName
		templateClone.PFP.Image = thumbnail
		templateClone.Parent = script.Parent.plrScroll

--if a player slot was clicked
		templateClone.MouseButton1Click:Connect(function()
			if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor -- Reset the current selected button's color
		end

			templateClone.BackgroundColor3 = templateClone and selectedColor or unselectedColor
			selectedButton = templateClone -- Rewrite the selectedButton

if templateClone and templateClone.BackgroundColor3 == selectedColor then
					plrchoiceUI.Enabled = true
					plrchoiceUI.Frame.question.Text = "Are you sure you would like to loopkill "..templateClone.Text.."?"
end
		end)
		
		-- the no button on the prompt
		yes.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
			loopkillPlr:Fire(templateClone, p)
		end)

dc7a8a64f8f7b8068301e0434cf3dd7d

1 Like

Use the Remote event in your own gui.You cant kill someone in client.

function updPlrs()
	local plr = game.Players.LocalPlayer
	local thumbnailtype = Enum.ThumbnailType.HeadShot
	local thumbnailsize = Enum.ThumbnailSize.Size420x420

	for i, p in pairs(game.Players:GetPlayers()) do
		if (script.Parent.plrScroll:FindFirstChild(p.Name)) then continue end
		local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)

		local templateClone = template:Clone()
		templateClone.Name = p.Name
		templateClone.Visible = true
		templateClone.Text = p.Name
		templateClone.displayName.Text = "@"..p.DisplayName
		templateClone.PFP.Image = thumbnail
		templateClone.Parent = script.Parent.plrScroll

--if a player slot was clicked
		templateClone.MouseButton1Click:Connect(function()
			if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor -- Reset the current selected button's color
		end

			templateClone.BackgroundColor3 = templateClone and selectedColor or unselectedColor
			selectedButton = templateClone -- Rewrite the selectedButton

if templateClone and templateClone.BackgroundColor3 == selectedColor then
					plrchoiceUI.Enabled = true
					plrchoiceUI.Frame.question.Text = "Are you sure you would like to loopkill "..templateClone.Text.."?"
end
		end)
		
		-- the yes button on the prompt
		yes.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
			loopkillPlr:FireServer(p)
		end)

Here is a server script:

local Remotevent = script.Parent.RemoteEvent

function LoopKillTarget(Target)
    while true do
    if Target and Target.Character and Target.Character:FindFirstChild("Humanoid") then
       Target.Character.Humanoid.Health = 0
        task.wait()
    end
    task.wait()
end

Remotevent.OnServerEvent:Connect(LoopKillTarget)
1 Like

hey gate, thank u so much for ur help. i really appreciate it.

i have all that script i put up above in a server script and it works but this part kills every player in the server rather than just the target.

this is what i got:

		-- the no button on the prompt
		yes.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
			selectedButton.BackgroundColor3 = unselectedColor
			local findPlr = plrs:FindFirstChild(templateClone.Text)
if findPlr and findPlr.Character and findPlr.Character:FindFirstChild("Humanoid") then
if findPlr.Character.Humanoid.Health > 0 then
	findPlr.Character.Humanoid.Health = 0
end
end
		end)
1 Like

Try changing this line of code to:

for i, p in ipairs(game.Players:GetPlayers()) do --if you use ipairs,which means you will loop each every player.but pairs wont.
1 Like

great idea but no luck unfortunately.

i tried something like this but still no luck.

		-- the no button on the prompt
		yes.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
			selectedButton.BackgroundColor3 = unselectedColor
			local findPlr = game.Players:GetPlayerFromCharacter(templateClone.Name)
			
if findPlr and findPlr.Character and findPlr.Character:FindFirstChild("Humanoid") then
if findPlr.Character.Humanoid.Health > 0 then
	findPlr.Character.Humanoid.Health = 0
end
end
		end)

got it! you kill every player in the ipairs() loop!

1 Like

wait wdym?

this is my script btw sorry shouldve uploaded:

local template = game.ReplicatedStorage.plrName
local plrs = game:GetService("Players")
local unselectedColor = Color3.fromRGB(199, 199, 199) -- grey/white
local selectedColor = Color3.fromRGB(97, 255, 62) -- Green
local plrchoiceUI = script.Parent.plrChoiceUI
local selectedButton -- Stores the button you clicked on
local plrchoiceUI = script.Parent.plrChoiceUI
local yes = plrchoiceUI.Frame.yes
local no = plrchoiceUI.Frame.no
local loopkillPlr = game.ReplicatedStorage:WaitForChild("loopkillPlr")

function updPlrs()
	local plr = game.Players.LocalPlayer
	local thumbnailtype = Enum.ThumbnailType.HeadShot
	local thumbnailsize = Enum.ThumbnailSize.Size420x420

	for i, p in ipairs(game.Players:GetPlayers()) do
		if (script.Parent.plrScroll:FindFirstChild(p.Name)) then continue end
		local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)

		local templateClone = template:Clone()
		templateClone.Name = p.Name
		templateClone.Visible = true
		templateClone.Text = p.Name
		templateClone.displayName.Text = "@"..p.DisplayName
		templateClone.PFP.Image = thumbnail
		templateClone.Parent = script.Parent.plrScroll

--if a player slot was clicked
		templateClone.MouseButton1Click:Connect(function()
			if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor -- Reset the current selected button's color
		end

			templateClone.BackgroundColor3 = templateClone and selectedColor or unselectedColor
			selectedButton = templateClone -- Rewrite the selectedButton

if templateClone and templateClone.BackgroundColor3 == selectedColor then
					plrchoiceUI.Enabled = true
					plrchoiceUI.Frame.question.Text = "Are you sure you would like to loopkill "..templateClone.Text.."?"
end
		end)
		
		yes.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
			selectedButton.BackgroundColor3 = unselectedColor
			local findPlr = plrs:FindFirstChild(templateClone.Text)
if findPlr and findPlr.Character and findPlr.Character:FindFirstChild("Humanoid") then
if findPlr.Character.Humanoid.Health > 0 then
	findPlr.Character.Humanoid.Health = 0
end
end
		end)


		no.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
selectedButton.BackgroundColor3 = unselectedColor
		end)
		
end
end


function removeSlot(plr)
	for i, child in pairs(script.Parent.plrScroll:GetChildren()) do
		if child.Name == plr.Name then
			child:Destroy()
		end
	end
end

updPlrs()
game.Players.PlayerAdded:Connect(updPlrs)
game.Players.PlayerRemoving:Connect(removeSlot)

you should make a function that loopkillstarget.and check if targets loopkilling abbraitube(i forgot the name of it :D) is false.if true.return.if false,set it true and start loopkilling.also if you wanna make stop all loopkills button,you should make a table that named LoopkillingPlayers.

You should move your killing function from the ipairs so you can solve it! (you need upgrades too.you gotta upgrade your script.)

This part:

local findPlr = game.Players:GetPlayerFromCharacter(templateClone.Name)
			
if findPlr and findPlr.Character and findPlr.Character:FindFirstChild("Humanoid") then
if findPlr.Character.Humanoid.Health > 0 then
	findPlr.Character.Humanoid.Health = 0
end
end
end)

Ok i upgraded it for your happines :slight_smile:

local template = game.ReplicatedStorage.plrName
local plrs = game:GetService("Players")
local unselectedColor = Color3.fromRGB(199, 199, 199) -- grey/white
local selectedColor = Color3.fromRGB(97, 255, 62) -- Green
local plrchoiceUI = script.Parent.plrChoiceUI
local selectedButton -- Stores the button you clicked on
local plrchoiceUI = script.Parent.plrChoiceUI
local yes = plrchoiceUI.Frame.yes
local no = plrchoiceUI.Frame.no
local loopkillPlr = game.ReplicatedStorage:WaitForChild("loopkillPlr")

function LoopKillTarget(Target)
    if Target and Target.Character and Target.Character:FindFirstChild("Humanoid") and if Target.Character.Humanoid.Health > 0 and Target:GetAttribute("LoopKilling") == true then
        Target.Character.Humanoid.Health = 0
    end
end

function updPlrs()
	local plr = game.Players.LocalPlayer
	local thumbnailtype = Enum.ThumbnailType.HeadShot
	local thumbnailsize = Enum.ThumbnailSize.Size420x420

	for i, p in ipairs(game.Players:GetPlayers()) do
		if (script.Parent.plrScroll:FindFirstChild(p.Name)) then continue end
		local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)

		local templateClone = template:Clone()
		templateClone.Name = p.Name
		templateClone.Visible = true
		templateClone.Text = p.Name
		templateClone.displayName.Text = "@"..p.DisplayName
		templateClone.PFP.Image = thumbnail
		templateClone.Parent = script.Parent.plrScroll

--if a player slot was clicked
		templateClone.MouseButton1Click:Connect(function()
			if selectedButton then
			selectedButton.BackgroundColor3 = unselectedColor -- Reset the current selected button's color
		end

			templateClone.BackgroundColor3 = templateClone and selectedColor or unselectedColor
			selectedButton = templateClone -- Rewrite the selectedButton

if templateClone and templateClone.BackgroundColor3 == selectedColor then
					plrchoiceUI.Enabled = true
					plrchoiceUI.Frame.question.Text = "Are you sure you would like to loopkill "..templateClone.Text.."?"
end
		end)
		
		yes.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
			selectedButton.BackgroundColor3 = unselectedColor
			local findPlr = plrs:FindFirstChild(templateClone.Text)
                        findPlr:SetAttribute("LoopKilling",true)
                        LoopKillTarget(findPlr)
		end)


		no.MouseButton1Click:Connect(function()
			plrchoiceUI.Enabled = false
                        local findPlr = plrs:FindFirstChild(templateClone.Text)
                        findPlr:SetAttribute("LoopKilling",false)
selectedButton.BackgroundColor3 = unselectedColor
		end)
		
end
end


function removeSlot(plr)
	for i, child in pairs(script.Parent.plrScroll:GetChildren()) do
		if child.Name == plr.Name then
			child:Destroy()
		end
	end
end

updPlrs()
game.Players.PlayerAdded:Connect(updPlrs)
game.Players.PlayerRemoving:Connect(removeSlot)

if it wont works please notice me >:)

1 Like

hey man, thanks a million for ur help. i tried the script but unfortunately it doesn’t work. i’m not quite sure what’s going on so im gonna get more opinions as well but if u have any other ideas please feel free to message! your response alone has made my day. :smiley:

EDIT:
hey man, someone fixed it for me, you were so close!

this had to be outside the function updPlrs:

yes.MouseButton1Click:Connect(function()
	plrchoiceUI.Enabled = false
	if selectedButton then
		selectedButton.BackgroundColor3 = unselectedColor
	end
	if selectedButton then
		local findPlr:Player = plrs:FindFirstChild(selectedButton.Text)
		if findPlr then
			if findPlr.Character and findPlr.Character:FindFirstChild("Humanoid") then
				if findPlr.Character.Humanoid.Health > 0 then
					findPlr.Character.Humanoid.Health = 0
				end
			end
		end
	end
end)

no.MouseButton1Click:Connect(function()
	plrchoiceUI.Enabled = false
	selectedButton.BackgroundColor3 = unselectedColor
end)