Problem with loop kill

the problem is is that it’ll kill sure but after a certain number of times it won’t change the player’s health to 0 to kill them. it’ll be really low instead. tysm! :smiley:

script:

plrcheckEvent.OnServerEvent:Connect(function(myplr, state)
	plrchoiceUI.Enabled = false

	--if clicked no
	if state == "no" then
		if selectedButton then
			selectedButton.ImageColor3 = unselectedColor
		end
	end

	--if clicked yes
	if state == "yes" then
		if selectedButton then
			selectedButton.ImageColor3 = unselectedColor
			local findPlr = plrs:FindFirstChild(selectedButton.Name)
			if findPlr and findPlr ~= myplr then
				closeUI:FireClient(myplr)
				if 	findPlr.Character.Humanoid.Health > 0 then
					findPlr.Character.Humanoid.Health = 0
					findPlr.CharacterAppearanceLoaded:Connect(function(c)
						wait(.5)
						local hum:Humanoid = c.Humanoid
						hum.Health = 0
					end)
				end
			else
				errorUIEvent:FireClient(myplr)
			end
		end
	end
end)

vid:

I get confused with Connections. They hurt my head because I never understand when they should be Disconnected.

But I noticed you are waiting for the CharacterAppearanceLoaded within the OnServerEvent:Connection.

Maybe that is causing issues. Two event connections within each other.

The issue might be that the character’s appearance was already loaded so the event wouldn’t fire.

I tried to work the problem and it works for the most part but I had some issues with an attribute bool I made that seems to reset along with the character reloading. Anyway here’s what I did, it kills the player over and over and you can find a way to automate it.

--//LOCALSCRIPT
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local button = script.Parent

button:GetAttributeChangedSignal("LoopKill"):Connect(function()
	local loopKillValue = button:GetAttribute("LoopKill")
	if loopKillValue then
		print("Attribute is true")
		RemoteEvent:FireServer(loopKillValue)
	else
		print("Attribute is false")
	end
end)

-- Toggle the LoopKIll attribute value when the button is clicked
button.MouseButton1Up:Connect(function()
	local currentLoopKillValue = button:GetAttribute("LoopKill")
	button:SetAttribute("LoopKill", not currentLoopKillValue)
end)


--//SERVERSCRIPT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local debounce = {} --attempting to silence multiple print entries

game.Players.PlayerAdded:Connect(function(player)
	debounce[player] = false

	player.CharacterAdded:Connect(function(character)
		RemoteEvent.OnServerEvent:Connect(function(player, bool)
			if not debounce[player] and bool == true and character and character:FindFirstChild("Humanoid") then
				debounce[player] = true
				local timer = 5

				while timer > 0 do
					print("Time till death ", timer)
					timer = timer - 1
					wait(1)
				end

				if character:FindFirstChild("Humanoid") then
					character.Humanoid.Health = 0
				end

				task.wait()
				debounce[player] = false
			end
		end)

		character.Humanoid.Died:Connect(function()
			repeat task.wait(1)
				print("Waiting for character to reload")
			until player.Character and player.Character:FindFirstChild("Humanoid")
		end)
	end)
end)

image

You can try this change:

findPlr.CharacterAppearanceLoaded:Connect(function(c)
	wait(.5)
	local hum:Humanoid = c.Humanoid
	hum:TakeDamage(hum.MaxHealth)
end)
1 Like