Players disappearing when Health set to 0

I’m working on a small game based off of the movie Circle in which players are spawned in and vote on who to kill each round. The last person standing wins.

I’ve added some effects when a player dies to make it more sci-fi like including a ragdoll effect, them being sucked into the center, and an electric zap using Buildthomas’s ElectricArc. The issue I’ve run into is that in some random cases, when the player is killed, their body just disappears instead of ragdolling and getting sucked in.

Here is a clip of the bug in action. THE FIRST DEATH YOU SEE (SUVORIA) IS THE INTENDED DEATH EFFECT. THE SECOND DEATH (ANVEXITY) IS THE GLITCH.

Keep in mind that I have literally no clue what’s causing this. :LoadCharacter() is never called in any script in the game, and the only time anyone’s position is set is when teleporting each player at the beginning of the round.

I do believe this was still happening before I added the ragdolling and electric arc, however I didn’t post about it now because it wasn’t very noticeable and thus less annoying when there were no death effects.

Another strange thing is that it happens on different players’ screens at different times, meaning the bug is client-sided and coming from a LocalScript. There are two main LocalScripts in my game: The RagdollHandler and the main handler for the GUI. The GUI literally does not mention position or .Died once except for :TweenPosition for GUIObjects, so I doubt it has anything to do with that script.

Even though I’m pretty sure the ragdolling has nothing to do with it, I figured I’d attach the script anyway to see if anyone could find anything. Keep in mind that this is straight from the toolbox and I just made adjustments to it to allow it to work for every player when they die instead of just the local one and to also drag them to the center before they respawn. Here it is:

repeat wait() until workspace.CurrentCamera ~= nil

local targ = workspace:WaitForChild("Map").Center.Ball.Position

local function NewHingePart()
	local B = Instance.new("Part")
	B.TopSurface = 0 B.BottomSurface = 0
	B.Shape = "Ball"
	B.Size = Vector3.new(1, 1, 1)
	B.Transparency = 1 B.CanCollide = true
	return B
end

local function CreateJoint(j_type, p0, p1, c0, c1)
	local nj = Instance.new(j_type)
	nj.Part0 = p0 nj.part1 = p1
	if c0 ~= nil then nj.C0 = c0 end
	if c1 ~= nil then nj.C1 = c1 end
	nj.Parent = p0
end

local AttactmentData = { 
	["RA"] = {"Right Arm", CFrame.new(0, 0.5, 0), CFrame.new(1.5, 0.5, 0), CFrame.new(1.5, 0, 0)},
	["LA"] = {"Left Arm", CFrame.new(0, 0.5, 0), CFrame.new(-1.5, 0.5, 0), CFrame.new(-1.5, 0, 0)},
	["RL"] = {"Right Leg", CFrame.new(0, 0.5, 0), CFrame.new(0.5, -1.5, 0), CFrame.new(0.5, -2, 0)},
	["LL"] = {"Left Leg", CFrame.new(0, 0.5, 0), CFrame.new(-0.5, -1.5, 0), CFrame.new(-0.5, -2, 0)},
}

local collision_part = Instance.new("Part")
collision_part.Name = "CP"
collision_part.TopSurface = Enum.SurfaceType.Smooth
collision_part.BottomSurface = Enum.SurfaceType.Smooth
collision_part.Size = Vector3.new(1, 1.5, 1)
collision_part.Transparency = 1

local camera = workspace.CurrentCamera
local players = game:GetService("Players")

local myPlr = players.LocalPlayer

function rag(char)
	print("Ragdolling " .. char.Name)
	char.Archivable = true
	local ragdoll = char:clone()
	char.Archivable = false

	local hdv = ragdoll:FindFirstChild("Head")

	for _, obj in pairs(char:GetChildren()) do 
		if not obj:IsA("Humanoid") then
			obj:destroy()
		end
	end

	local function scan(ch)
		for i = 1, #ch do
			scan(ch[i]:GetChildren())
			if (ch[i]:IsA("ForceField") or ch[i].Name == "HumanoidRootPart") or ((ch[i]:IsA("Weld") or ch[i]:IsA("Motor6D")) and ch[i].Name ~= "HeadWeld" and ch[i].Name ~= "AttachementWeld") then
				ch[i]:destroy()
			end
		end
	end
	scan(ragdoll:GetChildren())
	local function scanc(ch)
		for _, obj in pairs(ch:GetChildren()) do
			scanc(obj)
			if obj:IsA("Script") or obj:IsA("LocalScript") or ((obj:IsA("Weld") or obj:IsA("Motor6D")) and obj.Name ~= "AttachementWeld") or obj:IsA("ForceField") or (obj:IsA("Snap") and obj.Parent.Name == "Torso")
				or obj:IsA("ParticleEmitter")then
				obj:destroy()
			elseif obj:IsA("BasePart") then
				obj.Velocity = Vector3.new(0, 0, 0)
				obj.RotVelocity = Vector3.new(0, 0, 0)
				if obj.Parent:IsA("Accessory") then
					obj.CanCollide = false
				end
			end
		end
	end
	scanc(ragdoll)

	local fhum = ragdoll:FindFirstChild("Humanoid")
	fhum.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
	fhum.PlatformStand = true
	fhum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	fhum.Name = "RagdollHumanoid"

	local Torso = ragdoll:FindFirstChild("Torso")
	if Torso then
		Torso.Velocity = Vector3.new(math.random(), 0.0000001, math.random()).unit * 5 + (Vector3.new(0, 0.15, 0))
		local Head = ragdoll:FindFirstChild("Head")
		if Head and char == myPlr.Character then
			camera.CameraSubject = Head
			Head.face.Texture = "http://www.roblox.com/asset/?id=33328967"
			CreateJoint("Weld", Torso, Head, CFrame.new(0, 1.5, 0))
		elseif Head then
			Head.face.Texture = "http://www.roblox.com/asset/?id=33328967"
			CreateJoint("Weld", Torso, Head, CFrame.new(0, 1.5, 0))
		else
			print("No head!")
		end

		for att_tag, att_data in pairs(AttactmentData) do
			local get_limb = ragdoll:FindFirstChild(att_data[1])
			if get_limb ~= nil then

				local att1 = Instance.new("Attachment")
				att1.Name = att_tag
				att1.CFrame = att_data[2]
				att1.Parent = get_limb

				local att2 = Instance.new("Attachment")
				att2.Name = att_tag
				att2.CFrame = att_data[3]
				att2.Parent = Torso

				local socket = Instance.new("BallSocketConstraint")
				socket.Name = att_tag .. "_SOCKET"
				socket.Attachment0 = att2
				socket.Attachment1 = att1
				socket.Radius = 0
				socket.Parent = Torso

				get_limb.CanCollide = false

				local cp = collision_part:Clone()
				local cp_weld = Instance.new("Weld")
				cp_weld.C0 = CFrame.new(0, -0.25, 0)
				cp_weld.Part0 = get_limb
				cp_weld.Part1 = cp
				cp_weld.Parent = cp
				cp.Parent = ragdoll
			end
		end
	end
	ragdoll.Parent = workspace
	wait(2.5)
	local new = Instance.new("BodyPosition")
	new.Position = targ
	new.MaxForce = Vector3.new(4000,10000,4000)
	new.Parent = Torso
	wait(3)
	ragdoll:Destroy()
	fhum.MaxHealth = 100
	fhum.Health = fhum.MaxHealth
end

wait(1)
for _, plr in pairs (players:GetPlayers()) do
	print(plr.Name)
	plr.Character:WaitForChild("Humanoid").Died:Connect(function()
		rag(plr.Character)
	end)
end

workspace.ChildAdded:Connect(function(child)
	if child:IsA("Model") then
		local hum = child:WaitForChild("Humanoid", 0.5)
		if hum then
			hum.Died:Connect(function()
				rag(child)
			end)
		end
	end
end)

This bug has been pissing me off for the past day and I’ve been trying to solve it, but I can’t. Any help is highly appreciated.

Game link: https://www.roblox.com/games/6300548711/The-36

maybe you are causing some humanoid scripts to bug up here, try commenting it out

1 Like

I just did this then played for a bit and it happened again.

check the humanoid state when this happens and tell me what u see

What event would i watch for to print it? They respawn after 5 seconds, so do you want me to just print everyone’s state every second

do it however you can, just check the humanoid state when they die

1 Like

I just did this and one of the times I died, a player said I disappeared on his screen (on mine I got sucked in like intented). My state was Dead (checked as soon as Humanoid.Died fired)

So yea i saw your calling rag on death, see what happens if u dont call it

1 Like

So just disable the ragdoll effect and try?

1 Like

We couldn’t reproduce the bug with the ragdoll script disabled, after around 10 minutes of trying.

Seems thats your issue then, try examining into more of the ragdoll function

1 Like