In my game, players have the ability to morph into different characters. This mostly works fine, however sometimes, completely randomly, a player’s character will appear to have fallen apart on the screen of another person, even though the character appears and moves perfectly fine for the other player. This bug is a real problem, as it means the player who sees the ‘broken character’ can’t then interact with that player unless they rejoin the game:
I tried to fix this problem by ‘disabling death’, like so, but it does not appear to have worked:
local player = game.Players.LocalPlayer
local function disable_death(plr)
if plr ~= player then
local char = plr.Character
if not char or not char.Parent then
char = plr.CharacterAdded:wait()
end
local humanoid = char:WaitForChild("Humanoid")
humanoid:SetStateEnabled("Ragdoll",false)
humanoid:SetStateEnabled("Dead",false)
end
end
for i,plr in pairs(game.Players:GetChildren()) do
disable_death(plr)
end
workspace.ChildAdded:Connect(function(char)
local plr = game:GetService("Players"):FindFirstChild(char.Name)
if plr then
disable_death(plr)
end
end)
Any suggestions to fixing this ‘broken character’ bug?
FWIW, the code you posted seems to be working fine (even though they’ve fallen apart locally, they haven’t died – there is no empty, red healthbar). It’s more likely this is triggered by the morph code.
I’ve tried this on the client and server, before and after death, but it produces the error ‘BuildRigsFromAttachment is not a valid member of Humanoid’ each time.
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid:BuildRigsFromAttachment()
and
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
humanoid:BuildRigsFromAttachment()
end)
Have you had any success with this problem? It appears to happen more with a poor connection and when players join the game, but I can’t say for certain as it’s a hard to replicate.
So I think I’ve finally found a solution, however it’s very hacky and not ideal:
local function disable_death(plr)
if plr ~= player then
local char = plr.Character
if not char or not char.Parent then
char = plr.CharacterAdded:wait()
end
local humanoid = char:WaitForChild("Humanoid")
humanoid:BuildRigFromAttachments()
humanoid.Died:Connect(function()
for i = 1,10 do
humanoid:SetStateEnabled("Dead",false)
humanoid.Health = humanoid.MaxHealth
humanoid:BuildRigFromAttachments()
humanoid:ChangeState(Enum.HumanoidStateType.RunningNoPhysics)
wait(0.1)
end
end)
end
end
for i,plr in pairs(game.Players:GetChildren()) do
disable_death(plr)
end
workspace.ChildAdded:Connect(function(char)
local plr = game.Players:FindFirstChild(char.Name)
if plr then
disable_death(plr)
end
end)