Humanoid.Died function only running once

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make the player drop orbs when they die.
  2. What is the issue? Include screenshots / videos if possible!
    The death function only runs one time.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking in the dev forums. I also tried modifying the script a bit.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Tiers = require(game.ReplicatedStorage.Tiers)
local OrbMod = require(game.ServerScriptService.Orb)
game.Players.PlayerAdded:Connect(function(plr)
	while task.wait(0.25) do
		local hum = plr.Character:WaitForChild("Humanoid")
		local data = plr:WaitForChild("Data")
		data.Required.Value = Tiers.TierReq[data.Tier.Value]
		hum.WalkSpeed = 3 + (16 + math.pow(data.Tier.Value, 1.05)) + math.log(data.Power.Value, 40)
		hum.JumpPower = 10 + (35 + math.pow(data.Tier.Value, 1.025)) + math.log(data.Power.Value, 125)
		hum.MaxHealth = 100 + (math.pow(data.Tier.Value, 1.4)) * math.log(data.Power.Value, 2)
	end
end)

function SpawnOrbs(pos, exp)
	local exptodrop = exp/2
	local expmin = math.round(exp/100)
	local orbval = 0
	local orbID = 0
	local todrop = ""
	while exptodrop > expmin do
		for i, val in ipairs(OrbMod.Values) do
			if val > orbval and exptodrop - val >= expmin then
				orbval = val
				orbID = i
			end
		end
		exptodrop -= orbval
		todrop = Tiers.TierList[orbID]
		local clone = game.ServerStorage.OrbClone[todrop]:Clone()
		clone.Parent = workspace.Orbs
		clone.Position = pos
	end
end

game.Players.PlayerAdded:Connect(function(plr) --start of the function that doesn't work
	local bool = script.Died:Clone()
	bool.Parent = plr
	local data = plr:WaitForChild("Data")
	task.wait(0.5)
	plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth
	plr.Character.Humanoid.Died:Connect(function()
		plr:FindFirstChild("Died").Value = true
		SpawnOrbs(plr.Character.Torso.Position, data.Power.Value)
		data.Power.Value = 0
		data.Tier.Value -= 1
		task.wait(2)
		plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth
		plr:FindFirstChild("Died").Value = false
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

try to put the humanoid.died function on the first player.added before the loop (move the function up too)

1 Like
game.Players.PlayerAdded:Connect(function(plr) --start of the function that doesn't work
	plr.CharacterAdded:Connect(function(char)
		local bool = script.Died:Clone()
		bool.Parent = plr
		local data = plr:WaitForChild("Data")
		task.wait(0.5)
		char.Humanoid.Health = char.Humanoid.MaxHealth
		char.Humanoid.Died:Connect(function()
			plr:FindFirstChild("Died").Value = true
			SpawnOrbs(char.Torso.Position, data.Power.Value)
			data.Power.Value = 0
			data.Tier.Value -= 1
			task.wait(2)
			char.Humanoid.Health = char.Humanoid.MaxHealth
			plr:FindFirstChild("Died").Value = false
		end)
	end)
end)
1 Like

the player is given a new humanoid upon respawn, the old reference to the humanoid will no longer work, use player.CharacterAdded as well.

2 Likes

actually this is the right answer, i completely forgot about it since i was distracted with the infinite loop

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.