I want to make it so that my script runs for each player, updating a position value when you take damage so that if you die, a corpse can spawn which debris after 30 seconds. When you die, itll trigger a humanoid.died event which runs a seperate function thatll spawn corpse and etc. Right now, the function I made is pretty untested due to the fact I can’t reliably fire the events
Currently, I’ve tested this script multiple times by resetting, humanoid.died and humanoid.HealthChanged both go undetected around 75% of the time. I haven’t been able to create a solution for it, nor have I found a solution online that has worked for me.
I’ve also tried changing out humanoid with player:FindFirstChild("Humanoid) with the same results of sometimes working, sometimes not.
Also, I have a few questions.
If you die, will humanoid health changed fire before humanoid.died or no? If the answer is no, how would I be able to store the position of a character right before they died without a heartbeat or renderstepped event. If one of those events are needed, how would you go about with that.
Along with that, I’d like to know your ways of making corpses if they are efficient.
(Also ignore the starter character comments, I set them up so the lobby model wont count as a model, since I think startercharacters replace your default character and you’ll spawn as them, though I’m not too sure.)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
print(humanoid)
local oldHealth = humanoid.Health
print("Ran")
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
print("Ran")
--if character.Name == "StarterCharacter" then
if humanoid.Health < oldHealth then
player.Corpse.Value = character.HumanoidRootPart.Position
end
oldHealth = humanoid.Health
--else
-- return
--end
end)
--if character.Name == "StarterCharacter" then
humanoid.Died:Connect(function()
print('ran')
local Corpse = character:Clone()
character.Archivable = true
Killed(player,Corpse)
end)
--else
-- return
--end
end)
end)