Odd Humanoid death behaviour

I have a function that clones every part and accessory of the player’s character for an afterimage effect.
This function uses the Player.Character as an argument.
For some reason, when a character dies, an instance of the dead body is still being remembered and cloned in my afterimage function, which can be seen below. Notice how my character on the brown brick is also apart of the afterimage effect.


Now I’ve reset a couple of times and you’ll see all the different locations I’ve reset at.

I’ve tried to use Player:LoadCharacter() when the Humanoid.Health > 1 but nothing seems to work.
It’s like my past character models are being remembered into my new one or something.

Any idea on how to fix this odd behaviour?¨

Code and more context can be found in the replies by me.

Edit 2:

I went to a new place and the same behaviour persists.
My old dead characters are being cloned. You can literally see my dead characters parts on the ground:


The odd thing is these dead character parts also don’t exist anywhere in the workspace.

Here’s another example where I reset by the brown brick, and now you can see my old previous dead character being cloned and laying on the ground.


Sadly I can’t help you too well without seeing some of the code but it looks like you aren’t deleting the previous clones.

We can’t help you until we see your code.

No, I do definitely delete the clones. The issue is not the clones themselves. The other “afterimages” you’re seeing are the remains of my past character models.


What happens is not the clones not being deleted properly afterwards. The issue is that the character model that died, for some odd reason still gets remembered and cloned with the new character model.

So if I died 5 times in the game, it would clone 5 different character models, instead of just the one that’s sent as an argument.

I posted code in the replies with some more context

Would you mind properly indenting your code so it’s readable? It’s currently hard to tell if the code is erroring at the bottom before the call to Debris:AddItem happens.

Sorry but I’m not sure how you want me to indent it any differently than it already is. I can assure you though, it doesn’t error and the game:GetService("Debris"):AddItem(Model,1) works fine.

As demonstrated in this GIF, the model is destroyed after 1 second:


Would you mind showing us more of the code? For example, the function that calls the “CreateAfterImage” function?

		EffectModule:AfterImage(Character, 3, .15)

function EffectModule:AfterImage(Character, Iterations, Time)
	for i = 1,Iterations do

The Character parameter is literally just Player.Character from a local script


So I’m pretty sure this happens because the Roblox character is not being destroyed properly on Humanoid death. I tried to do this in a server script, and even after destroying the character, it still prints out Shurikanz, when I had expected it to print nil.


I think this is expected behaviour. Destroy does not remove a value from a variable or property (It sets it’s parent to nil and disconnects all connections), for example:

local part = Instance.new(“Part”)

You can set Player.Character = nil if you want to clear the Player.Character property.


Alright, so I tried to say:

			Player.Character = nil

And then I walked onto a black brick to highlight where I’m standing at. I reset ontop of the black brick and my character has its joints broken. I then respawn as a new character, and my local script now has a reference to this new character. When I run my function, my previous dead character, with all its joints broken, is still being cloned however ontop of the black brick:


I then reset myself 3 more times, which now makes it clone 4 of my previous old character models. The only solution I’ve found to get rid of the character models is to rejoin the game, but resetting/dying will still result in this odd behaviour:


I don’t know if this has something to do with R15 specifically or same thing occurs with R6. I definitely do not have any reference to old character models, so I don’t understand why this happens. As seen in my code, I have tried to set Player.Character = nil prior to loading a new character, and the issue still persists.


The cloning happens all client side. However, it’s only the local player that sees these dead clones of character models. If I FireServer and the server FireAllClients with the relevant Character as parameter, to render the same afterimages, they do not have this issue

I think you need to provide more code showing the circumstances under which EffectModule:AfterImage is called for us to be able to help with this issue.

One tactic I would recommend for debugging issues like this is try breaking it down into the simplest possible reproduction of the issue, just a script that calls CreateAfterImage in a while true do loop on an empty baseplate with none of the rest of the code in your game.


I deleted everything from my code that wasn’t necessary for the afterimage function to run at a completely new fresh place. As I expected it still happens:


Are you confident that it’s an issue with my code, and not how Roblox handles characters upon humanoid death on the client? As mentioned earlier, this issue is only seen by the local player, and only happens upon humanoid death. Simply rejoining the game will get rid of any reference to previous character models. I do not store the old character model in anyway, I’m pretty sure. I’ve been testing for hours now, so I can’t help but think this is not an issue with my code, but how humanoid death works in the background for the client.

I made the place uncopylocked for testing.
Everything can be found sindie the StarterGui → Client.

Client requires the environment module script.
The environment module script handles player input, in this case double tapping W.
The effectmodule handles the afterimage function.


Link: https://www.roblox.com/games/4814117502/Shurikanzs-Place-Number-94

So after debugging at the new place, I found out that the module script remembers the old instance of the character model, and that information carries over once you require the module again, and again and so on. So what I did was add this in my module script:

	Character = nil

And now it works as intended :smiley:

At first I was setting the Character = nil server-side, but I failed to remember that this issue only onccured on the client, so of course I had to set it to nil on the client haha.

You could also do this in a character-bound script so that it automatically resets itself.