Script simply won't fire function. no clue why

So basically the code simply won’t print the “Player Died” when the player dies. can’t for the life of me figure out why.

i = 0
game.Players.PlayerAdded:Connect(function(plr)
	plr:LoadCharacter()
	plr.CharacterAdded:Connect(function(char)
		print("Character Loaded")
		char:WaitForChild("Humanoid").Died:Connect(function()
			print("Player Died")
			i = 1
			local rope = Instance.new("RopeConstraint", game.Workspace.RopeTarget)
			local a0 = Instance.new("Attachment", game.Workspace.RopeTarget)
			local a1 = Instance.new("Attachment", char.HumanoidRootPart)
			rope.Attachment1 = a1
			rope.Attachment0 = a0
			a0.CFrame = game.Workspace.RopeTarget.CFrame
			a1.CFrame = char.HumanoidRootPart.CFrame
			rope.WinchEnabled = true
			rope.WinchTarget = .5
			while wait() and i == 1 do
				if rope.Length == rope.WinchTarget then
					i = 0
					plr:LoadCharacter()
				end
			end
		end)
	end)
end)

fixed it, for some reason i had to add the loadcharacter to the bottom or it wouldn’t fire the function

The reason you had to move LoadCharacter down was because you loaded the character, then ran CharacterLoaded. CharacterLoaded runs when the character is loaded, but you loaded the character before CharacterLoaded could recognize that.

2 Likes